我在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