I'm working on a project, and I got to the point where I need to remove any duplicates from the main list. I've got three lists here, and I'm trying to eliminate duplicates in the flight_ID list. I managed to do it, but unfortunately, I couldn't remove other elements that are associated with the removed ones in the flight_ID list.
# All lists have a length of 20
flight_ID = ['1064662221', '1064617390', '1064614152', '1064614152', \
'1064775880', '1064645826', '1064645826', '1064664535', '1064659772', \
'1064659772', '1064614050', '1064614050', '1064614286', '1064614286', \
'1064614286', '1064614286', '1064614286', '1064614286', '1064614286', '1064646536']
flight_number = ['1827', '1585', '8409', '1465', '30', '9188', '2232', '3760', '579', '3309', '1259', '2193', '6566', '2231', '5214', '8601', '3169', '1601', '7832', '335']
airline_Code = ['TK', 'AY', 'DL', 'AF', 'FX', 'UA', 'LH', 'U2', 'SK', 'A3', 'AF', 'KL', 'VS', 'UX', 'G3', 'UU', 'KQ', 'AF', 'AR', 'LO']
I used the following function to remove duplicates from the main list:
def remove_dup(a):
i = 0
while i < len(a):
j = i + 1
while j < len(a):
if a[i] == a[j]:
del a[j]
else:
j += 1
i += 1
remove_dup(flight_ID)
# OUTPUT
['1064662221', '1064617390', '1064614152', '1064775880', '1064645826', '1064664535', '1064659772', '1064614050', '1064614286', '1064646536']
# 10 elements have been removed.
Now, as I described above, I need to do the same thing with the other lists, so Items matching items in the main list (flight_ID) are also removed.
NOTE: Although the main list shows duplicate items, other lists' items DON'T