logo-MindMajix
PostPythonPython
r
rushi chowdary

Posted on 20th July 2024|1088 views

0
votes

Converting Text File To Dictionary Python

How to convert text file into a dictionary in python?

1 answers
Answers
P
Aryan Sharma

Posted on 20th July 2024| views

  1. import json filename = 'commands.txt' commands = {} with open(filename) as fh: for line in fh: command, description = line. strip(). split(' ', 1) commands[command] = description. ...
  2. >>> line. strip(). ...
  3. >>> line. split(' ', 1) ['ABBREV', ' Abbreviation processsor\n'] >>> line.

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo

  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos
Name
Course *
Email *
Phone Number