Python:将每行单词放入列表中

这个问题在这里已经有了答案:

  • 在Python中,如何逐行读取文件到列表中? 35个答案

  • 我不知道你为什么使用分割功能。 相反,我认为下面的列表理解会帮助你。

    f = open('animal.txt','r')
    myList = [line.strip() for line in f]
    f.close()
    

    希望能帮助到你。

    链接地址: http://www.djcxy.com/p/42351.html

    上一篇: Python: put each line of words in a list

    下一篇: Each line an element in an array when reading text file in Python