Python: put each line of words in a list

This question already has an answer here:

  • In Python, how do I read a file line-by-line into a list? 35 answers

  • Im not sure why you used the split function. Instead i think the following list comprehension will help you.

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

    Hope it helps.

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

    上一篇: 我如何从一个文件存储到Python中的数组?

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