「food.txt」というファイルから食料品を読み取って一覧表示する python 関数を作成する必要があります。これにより、テキストファイルに新しい行が見つかるたびに、一般的なリスト内にグループ化された新しいリストが作成されます。
food.txt:
milk
cheese
bread
steak
chicken
potatoes
^ 各単語は、グループ間に 1 つの改行を入れて、独自の行に配置する必要があります
出力: [['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