我试着用每天在学校吃的午餐,从API(一个普通的&;素食主义者的选择)。有时学校关门时,名单上只有一个项目。下面是我从api得到的列表的翻译版本:
[['Closed'], ['Pasta Al Carne with shredded beef, tomato salsa and grated cheese', 'Pasta with ratatouille'], ['Pancake with cottage cheese and jam', 'Pancake with cottage cheese and jam'], ['Breaded fish fillet with cold sauce boiled potatoes', 'Vegetarian moussaka'], ['Hamburgers with bread and classic accessories',' Vegetarian burgers with classic accessories']]
现在我有这个密码:
"Monday: {}\nTuesday: {}\nWednesday: {}\nThursday: {}\nFriday: {}".format(*lunch)
输出到:
Monday: ['Closed']
Tuesday: ['Pasta Al Carne with shredded steak, tomato salsa and grated cheese', 'Pasta with ratatouille']
etc...
我怎样才能把每一天单独格式化,使它看起来更像这样
Monday: Closed
Tuesday: Pasta Al Carne with shredded steak, tomato salsa and grated cheese. Vegetarian: Pasta with ratatouille
Wednesday: Pancake with cottage cheese and jam. Vegetarian: Pancake with cottage cheese and jam
etc...
我已经搜索了一段时间如何在Python中格式化列表,但是由于我是新手,所以很难知道要搜索什么。 谢谢
午餐=[['关闭'],['牛肉丝、番茄沙拉和磨碎奶酪意大利面','鼠尾草意大利面'],['白干酪和果酱煎饼',['白干酪和果酱煎饼'],['冷沙司煮土豆面包鱼片','素食穆萨卡'],['面包和经典配饰汉堡包',“经典配饰素食汉堡”]] 天=['星期一','星期二','星期三','星期四','星期五']
输出:
这里需要一个简单的
join
:这里的技巧是
str.join
函数,它允许您使用字符串,在我们的例子中是“,”作为列表项的分隔符相关问题 更多 >
编程相关推荐