簡體   English   中英

我該如何安排這個 function 所以它返回一個包含所有這些列表的列表

[英]How can I arrange this function so it returns a list with all this lists on it

所以我一直在做一個項目,我只能使用Tkinter。 問題是我需要我在別人的問題中找到的這個 function 返回一個列表,其中的列表已經打印,但我找不到實現這一點的方法。 目前,它會為 .txt 文件中的每一行打印一個列表,並且在每個列表中都有它所指的行的單詞。 我需要它來做到這一點,但所有那些列表,它的打印應該 go 在一個列表中。 我對此很陌生,很抱歉這個愚蠢的問題:

    def file_to_list(file):
        stop_words=open(file,'r') 
        lines = [line.split() for line in stop_words]
        for line in lines:
            print(line)

你已經有了答案

def file_to_list(file):
    stop_words=open(file,'r') 
    lines = [line.split() for line in stop_words]
    print(lines)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM