将列表列表放入Python丰富的表中
鉴于以下情况,我如何将动物、年龄和性别输入每个表格单元格?目前,所有数据都在一个单元格中结束。谢谢将列表列表放入Python丰富的表中,python,rich,Python,Rich,鉴于以下情况,我如何将动物、年龄和性别输入每个表格单元格?目前,所有数据都在一个单元格中结束。谢谢 from rich.console import Console from rich.table import Table list = [['Cat', '7', 'Female'], ['Dog', '0.5', 'Male'], ['Guinea Pig', '5', 'Male']] table1 = Table(show_header=True, he
from rich.console import Console
from rich.table import Table
list = [['Cat', '7', 'Female'],
['Dog', '0.5', 'Male'],
['Guinea Pig', '5', 'Male']]
table1 = Table(show_header=True, header_style='bold')
table1.add_column('Animal')
table1.add_column('Age')
table1.add_column('Gender')
for row in zip(*list):
table1.add_row(' '.join(row))
console.print(table1)
只需使用
*
解包元组,它就可以正常工作
for row in zip(*list):
table1.add_row(*row)
注意
table1.add_row(*('Cat', 'Dog', 'Guinea Pig'))
相当于
table1.add_row('Cat', 'Dog', 'Guinea Pig')
table1.add_row('Cat Dog Guinea Pig')
而以前你的方法相当于
table1.add_row('Cat', 'Dog', 'Guinea Pig')
table1.add_row('Cat Dog Guinea Pig')
富人的定义是什么<代码>表格?是外包装吗?对不起,我弄错了-错过了进口。啊!非常感谢。