Python 元组列表中的时间戳差异

Python timestamp difference in list of tuples

我在元组列表中有 FROM Timestamp 和 TO Timestamp。我想获得元组列表中存在的以分钟为单位的时间戳差异。

例如:

Timestamp_list = [
    (Timestamp("2021-09-13 07:00:00"), Timestamp("2021-09-13 10:00:00")),
    (Timestamp("2021-09-13 11:00:00"), Timestamp("2021-09-13 12:00:00")),
]

在上面的列表中,Timestamp('2021-09-13 07:00:00')Timestamp('2021-09-13 10:00:00')之间的差异是180分钟,Timestamp('2021-09-13 11:00:00')Timestamp('2021-09-13 12:00:00')之间的差异是60 分钟。我总共有 240 分钟。列表中可能有 N 个 FROM 和 TO Timestamp。

预期结果应该是 240 分钟。你能帮我在 Python 完成这件事吗?谢谢。

尝试:

out = sum((b - a).seconds for a, b in Timestamp_list) // 60
print(out)

打印:

240