Reading from a plain text file

后端 未结 4 885
天涯浪人
天涯浪人 2020-12-11 08:24

Say I have the following in a text file:

car
apple
bike
book

How can I read it and put them into a dictionary

4条回答
  •  粉色の甜心
    2020-12-11 08:34

    This is covered pretty thoroughly in the Python tutorial.

    lines = open('filename.txt', 'r').readlines()
    

提交回复
热议问题