第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何查明字典中的時間是否有關(guān)聯(lián)?

如何查明字典中的時間是否有關(guān)聯(lián)?

慕碼人8056858 2023-12-12 09:56:29
這是我的所有代碼:shaped_timevalues = dict()from datetime import datetimefmt = '%H:%M:%S'newlist= list()for i,j in time_values.items():    print('SEGMENTD:',i)    for one in range(len(j)-1):        one_hour = datetime.strptime(str(j[one]), fmt).strftime("%H")        one_min = datetime.strptime(str(j[one]), fmt).strftime("%M")        other_hour = datetime.strptime(str(j[one + 1]), fmt).strftime("%H")        other_min = datetime.strptime(str(j[one + 1]), fmt).strftime("%M")        if one_hour== other_hour and int(one_min) +10>= int(other_min):            newlist.append(['%s:%s'%(one_hour,one_min),'%s:%s'%(other_hour,other_min)])            shaped_timevalues.setdefault(i, []).append(['%s:%s'%(one_hour,one_min),'%s:%s'%(other_hour,other_min)])        else:            shaped_timevalues.setdefault(i, []).append(['%s:%s' % (one_hour, one_min)])print(newlist)print(shaped_timevalues)它需要兩個值,有時會重復。輸出如下:Edit2:因此,我想創(chuàng)建一個新的字典,如果值(時間)在段中連接,例如在5874022、'00:03:00'、'00:08:00'和'00:14:00'時間中鏈接,因此它們必須是該字典中的列表。結(jié)果應(yīng)該是這樣的:time_values = {'5874022': ['00:03:00', '00:08:00', '00:14:00'],                           ['07:43:00'], ['09:33:00'], ['17:18:00'], ['23:23:00'], ...}
查看完整描述

1 回答

?
翻閱古今

TA貢獻1780條經(jīng)驗 獲得超5個贊

我使用你的代碼作為基線,然后構(gòu)建了以下內(nèi)容:


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)

查看完整回答
反對 回復 2023-12-12
  • 1 回答
  • 0 關(guān)注
  • 132 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號