gpt4 book ai didi

python - 如何使输出的最后一列仅包含列表的每个元素而不是整个列表?

转载 作者:太空宇宙 更新时间:2023-11-03 19:41:31 28 4
gpt4 key购买 nike

我正在使用 python 来排列列中某些列表中的数据。我遇到问题,因为最后一列包含列表中的所有元素,而不是每行的每个元素。

代码:

from datetime import datetime

list = [5275116,5275140,5275164,5275188,5275212,5275236,5275260,5275284,
5275308,5275332,5275356,5275380,5275404,5275428,5275452,5275476,
5275500,5275524,5275548,5275572,5275596,5275620,5275644,5275668,
5275692,5275716,5275740,5275764,5275788,5275812,5275836,5275860,
5275884,5275908,5275932,5275956]

timestamp = [i * 300 for i in list]

for ts in timestamp:
for element in list:
print("{} - Auction Nr. - {}".format(datetime.fromtimestamp(ts), list))

我的输出最终看起来像这样(只是其中的一部分):

2020-02-27 08:00:00 - Auction Nr. - [5275116, 5275140, 5275164, 5275188, 5275212, 5275236, 5275260, 5275284, 5275308, 5275332, 5275356, 5275380, 5275404, 5275428, 5275452, 5275476, 5275500, 5275524, 5275548, 5275572, 5275596, 5275620, 5275644, 5275668, 5275692, 5275716, 5275740, 5275764, 5275788, 5275812, 5275836, 5275860, 5275884, 5275908, 5275932, 5275956]
2020-02-27 08:00:00 - Auction Nr. - [5275116, 5275140, 5275164, 5275188, 5275212, 5275236, 5275260, 5275284, 5275308, 5275332, 5275356, 5275380, 5275404, 5275428, 5275452, 5275476, 5275500, 5275524, 5275548, 5275572, 5275596, 5275620, 5275644, 5275668, 5275692, 5275716, 5275740, 5275764, 5275788, 5275812, 5275836, 5275860, 5275884, 5275908, 5275932, 5275956]

我希望每一行看起来像这样:

2020-02-24 10:00:00 - Auction Nr. - 5275116

谢谢!

Bouns:如何将时间转换为 UTC?目前是 UTC+1

最佳答案

这会同时迭代时间戳和 list_(我添加了下划线,这样您就不会遮盖内置关键字 list):

from datetime import datetime

list_ = [5275116,5275140,5275164,5275188,5275212,5275236,5275260,5275284,
5275308,5275332,5275356,5275380,5275404,5275428,5275452,5275476,
5275500,5275524,5275548,5275572,5275596,5275620,5275644,5275668,
5275692,5275716,5275740,5275764,5275788,5275812,5275836,5275860,
5275884,5275908,5275932,5275956]

timestamp = [i * 300 for i in list_]

for ts, el in zip(timestamp, list_):
print("{} - Auction Nr. - {}".format(datetime.fromtimestamp(ts), el))

关于python - 如何使输出的最后一列仅包含列表的每个元素而不是整个列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60396746/

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