我需要創建一個python函數,該函數從名爲「food.txt」的文件中讀取和列出雜貨,以便在找到文本文件中的新行時,通用列表中的新列表分組爲創建。列表的有序列表
food.txt:
milk
cheese
bread
steak
chicken
potatoes
^每個詞應該是對自己符合羣體
輸出之間的一個新行:[ '牛奶', '奶酪','麪包'],[' 牛排」, '雞', '土豆']
到目前爲止,我有:
def build_grocery_list(file_name):
outer_list=[]
inner_list=[]
food_list=open(file_name,"r")
for line in food_list:
line.strip('\n') # no white spaces in the list
非常感謝你jason :) – pythonnoob