我在python中使用日期。使用其他列表的重複項刪除項目列表
d = []
t = []
for row in cursor:
emp = row[2] #employee ID
logtype = row[4] # 'I' For login, 'O' for logout.
log = row[3] # time
day = log.strftime("%d")
month = log.strftime("%m")
year = log.strftime("%y")
times = log.strftime("%I:%M")
if (logtype == 'I') :
d.append(day)
t.append(times)
#the problem
time = list(set(t)) #len(22)
day = list(set(d)) #len(23)
RESULT
Day = ['03', '04', '05', '06', '07', '09', '10', '11', '11', '12', '13', '14', '17', '18', '19', '20', '21', '23', '24', '25', '26', '27', '28']
Time = ['08:05', '08:01', '08:08', '10:33', '08:05', '06:53', '08:15', '08:03', '08:06', '08:11', '08:05', '08:03', '09:23', '08:10', '08:05', '08:10', '08:26', '01:43', '08:01', '08:10', '01:14', '08:06', '08:06']
欲同時其在時間值,以除去所述重複天(11)。
UPDATE
from collections import Counter
#identify repeating day in dex number duplicate
dup = [i for key in (key for key, count in Counter(day).items() if count > 1) for i, x in enumerate(day) if x == key]
我設法找到重複使用上述代碼然後我刪除其他除重複最後一次出現,然後通過下面的代碼
for x in dup[:-1]:
time.pop(x)
day.pop(x)
day2.append(adlaw)
time2.append(time)
附加的指針
請編輯您的問題並添加您嘗試過的代碼。它工作嗎? – 2016-11-22 09:50:44
我很困惑*「如何使用Day的重複值在Time中刪除列表項」*但您的'Day'已經具有唯一值,對嗎?還請提一下你想要的列表結構以及你試圖達到的目標。 –
因此你想刪除'08:06',因爲'Day'中有兩個'11'? – Keiwan