我有一个以分和秒表示时间的字符串列表,例如
distanceList = [0.56, 0.04, 0.56, 0.44, 0.76] #represents distances traveled
timeList = ['5m:11s', '18m:18s', '13m:35s', '8m:26s', '121m:7s'] # represents time to taken to travel
我需要提取这些数字(分(m)和秒(s))并转换成小时。你知道吗
到目前为止,我已经实现了zip函数,并使用了一些列表理解来将数字单独提取到列表中。然而,我不知道如何把这些时间加起来,因为它们是分开的,而且与结肠分隔符的距离并不总是一致的。我就这么走了。你知道吗
for a, b in zip(distanceList, timeList):
nums = [item for subitem in b for item in subitem.split() if item.isdigit()]
print nums
预期结果:表示分和秒的整数列表。你知道吗
[[5,11],[18,18]...]
收到的结果:
['5', '1', '1', '1', '8', '8'....]
如果“summing into hours”仍然相关:sum
timedelta
对象。你知道吗加5美分
输出
或:
输出:
相关问题 更多 >
编程相关推荐