Python: Create Dictionary from Text/File that's in Dictionary Format

后端 未结 6 498
长情又很酷
长情又很酷 2020-12-14 16:32

I\'d like to create a dictionary from a text file that I have, who\'s contents are in a \'dictionary\' format. Here\'s a sample of what the file contains:

6条回答
  •  一整个雨季
    2020-12-14 17:00

    It's not a production ready solution and may not work well with a file of your size, but if you need a simple way and can prepend you file to

    my_dict = {'fawn': [1], 'sermersheim': [3], 'sonji': [2], 'scheuring': [2]}
    

    then you can rename it to a python file and simply import

    from my_file import my_dict 
    

提交回复
热议问题