1 回答
TA贡献1780条经验 获得超5个赞
我使用你的代码作为基线,然后构建了以下内容:
shaped_timevalues = dict()
from datetime import datetime
fmt = '%H:%M:%S'
for i,j in time_values.items():
newlist = list()
sequence = [j[0]] #list with the 'linked times', with the first value already inserted
for n in range(1, len(j)):
time1 = datetime.strptime(j[n-1], fmt)
time2 = datetime.strptime(j[n], fmt)
minutes = (time2 - time1).total_seconds()/60 #how many minutes in difference
if minutes == 5 or minutes == 6:
sequence.append(j[n])
else:
newlist.append(sequence)
sequence = [j[n]]
if len(sequence) > 0:
newlist.append(sequence)
shaped_timevalues[i] = newlist
print(shaped_timevalues)
添加回答
举报