Post

PythonPython

r
rushi chowdary

Posted on 19th April 2024|1067 views

0
votes

Converting Text File To Dictionary Python

How to convert text file into a dictionary in python?

Answers
P
Aryan Sharma

Posted on 19th April 2024

  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