gpt4 book ai didi

python - 转换 for 循环的列表输出

转载 作者:行者123 更新时间:2023-11-28 21:57:19 26 4
gpt4 key购买 nike

for line in inputFile: #here is 5 lines
data = [['Text', 'Count'], [var1, var5]]
print data

输出:

[['Text', 'Count'], ['Test', 156]]
[['Text', 'Count'], ['Test5', 154]]
[['Text', 'Count'], ['Test6', 156]]
[['Text', 'Count'], ['Test8', 178]]
[['Text', 'Count'], ['Testg', 144]]

我怎样才能以这种方式输出:

[['Text', 'Count'], ['Test', 156], ['Test', 156], ['Test', 156],['Test', 156],['Test', 156]]

我可以将我的输出转换为这种方式吗?

最佳答案

只需将每个数据附加到列表中:

L = [['Text', 'Count']]
for line in inputFile:
L.append([var, var5])

关于python - 转换 for 循环的列表输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19973632/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com