Python reads the file, skips spaces, and stores the words of each line in a List

Python reads the file, skips spaces, and stores the words of each line in a List:

Code:

f = open("doc_1_Windex.txt","r", encoding='utf-8')

lines = f.readlines()#read all content


for i in range(0,lines.__len__(),1): #(start/left boundary, end/right boundary, step)

    list = [] ## empty list, store the i-th row data in the list
    for word in lines[i].split():
         word=word.strip(string.whitespace)
         list.append(word);
    print(list)



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325703159&siteId=291194637
Recommended