python - Failing to retrieve difference between two lists -
set-up
i have 2 lists containing unique id
's: tl
, yl
.
an id
looks '97678410'
.
len(tl) = 185
, len(yl) = 182
.
problem
i need difference between 2 lists. is, want obtain list containing id
's in tl
not in yl
.
i've considered following answers,
- https://stackoverflow.com/a/3462160/7326714
- https://stackoverflow.com/a/3462202/7326714
- https://stackoverflow.com/a/3462164/7326714
but code,
final = [id id in tl if id not in yl]
yields final
copy of tl
.
i have checked, , there id
's both in tl
in yl
.
see 2 lists here.
tl = ['97682631', '97682633', '97684139', '97680023', '97680021', '97678410', '97675792', '97673883', '97673946', '97671417', '97664888', '97666272', '97667377', '97670240', '97664192', '97655130', '97655288', '97655289', '97655293', '97645033', '97645101', '97632355', '97633891', '97616084', '97608150', '97606844', '97602650', '97584169', '97595622', '97583025', '97577940', '97569579', '97570582', '97565137', '97540897', '97539337', '97518058', '97518763', '97512249', '97512252', '97493818', '97489271', '97489272', '97461011', '97459708', '97456572', '97456626', '97456632', '97453137', '97454483', '97454693', '97454892', '97450659', '97446162', '97446168', '97434415', '97436210', '97427637', '97427635', '97427632', '97425356', '97417309', '97404715', '97404716', '97404718', '97392000', '97392111', '97386620', '97383091', '97384274', '97384337', '97383090', '97383089', '97366670', '97361744', '97361698', '97361701', '97361702', '97361722', '97276849', '97272708', '97236813', '97223049', '97213666', '97174233', '97164586', '97141165', '97141170', '97145252', '97136643', '97130696', '97042669', '97036543', '97007304', '96915042', '96887981', '96883537', '96865568', '96818145', '96818147', '96776783', '96767917', '96747326', '96747763', '96735976', '96739100', '96712470', '96714575', '96695120', '96667787', '96561238', '96583133', '96558744', '96553823', '96528225', '96389164', '96377527', '96251693', '96269789', '96246548', '96171491', '96161689', '96153980', '96131831', '96131903', '96131956', '96131749', '96126777', '96101829', '95958417', '95914030', '95735741', '95656954', '95503961', '95501454', '95502625', '95474681', '95468325', '95472748', '95474209', '95440076', '95443633', '95408190', '95276367', '95222901', '95218637', '95218977', '95187313', '94948878', '94806104', '94306925', '94097967', '94018001', '94090391', '93860264', '93423007', '93206111', '92251067', '92480603', '91550754', '89421778', '89658137', '89123891', '88860045', '88903715', '88169920', '85395060', '83483635', '82819637', '81788095', '80286689', '76733816', '74983036', '75270743', '72079817', '69163539', '66080651', '62508733', '58272006', '58927395', '59487908', '59764478', '57909458', '51546448', '41278948'] yl = [97655130, 97645101, 97642334, 97642352, 97633891, 97636938, 97632355, 97616084, 97606844, 97608150, 97605869, 97602650, 97584169, 97595622, 97583025, 97577940, 97574727, 97569579, 97570582, 97566414, 97565137, 97540897, 97539337, 97518058, 97518763, 97512252, 97512249, 97493818, 97489271, 97489272, 97461011, 97459708, 97456572, 97456626, 97456632, 97453137, 97454483, 97454693, 97454892, 97446162, 97446168, 97450659, 97436210, 97434415, 97427632, 97427635, 97427637, 97425356, 97417309, 97404718, 97404715, 97404716, 97392000, 97392111, 97392693, 97386620, 97383091, 97384274, 97384337, 97383090, 97383089, 97366670, 97361698, 97361701, 97361702, 97361722, 97361744, 97362574, 97276849, 97272708, 97236813, 97223049, 97213666, 97205682, 97174233, 97164586, 97141165, 97141170, 97145252, 97136643, 97130696, 97129530, 97042669, 97036543, 97007304, 96915042, 96890889, 96890891, 96883537, 96865568, 96818147, 96818145, 96801213, 96776783, 96767917, 96747326, 96747763, 96735976, 96739100, 96712470, 96714575, 96704316, 96695120, 96583133, 96558744, 96561238, 96553823, 96528225, 96466854, 96389164, 96377527, 96306028, 96251693, 96269789, 96246548, 96171491, 96153980, 96161689, 96131956, 96126777, 96131749, 96131831, 96131903, 96101829, 95958417, 95914030, 95735741, 95656954, 95503961, 95501454, 95502625, 95474681, 95468325, 95472748, 95474209, 95440076, 95443633, 95408190, 95276367, 95222901, 95218637, 95218977, 95187313, 95192968, 94948878, 94806104, 94306925, 94170831, 94097967, 94018001, 94090391, 93423007, 93206111, 92480603, 92251067, 91550754, 89865094, 89421778, 89658137, 89123891, 88860045, 88903715, 88169920, 85395060, 83483635, 82819637, 81788095, 80260371, 80286689, 76733816, 74983036, 75270743, 72079817, 69163539, 66080651, 62508733, 59487908, 59764478, 58272006, 58927395, 51546448, 41278948]
i'm pretty sure it's stupid thing, code works simple example.
how obtain final
containing id
's in tl
not in yl
?
tl = ['97682631', '97682633', '97684139', '97680023',........., '51546448', '41278948'] yl = [97655130, 97645101, 97642334, 97642352,.........., 51546448, 41278948] tl_unique = set(tl) # make sure current list contain set of unique values yl_unique = set(yl)
above 2 lines not necessary if sure not having duplicate values otherwise duplicate values compared
diff = [int(i) in tl_unique if int(i) not in yl_unique] # element in yl in integer , in tl string used int(i) compare integer value of element in tl_unique print(diff)
Comments
Post a Comment