I want to compare a list of lists where each sublist contains two strings (ID, and Time-stamp) and a sub-list of members. I have the following list of lists:
node = [['1001', '2008-01-06T02:12:13Z', ['']],
['1002', '2008-01-06T02:13:55Z', ['']],
['1003', '2008-01-06T02:13:00Z', ['Lion', 'Rhinoceros', 'Leopard', 'Panda']],
['1004', '2008-01-06T02:15:20Z', ['Lion', 'Leopard', 'Eagle', 'Panda', 'Tiger']],
['1005', '2008-01-06T02:15:48Z', ['Lion', 'Panda', 'Cheetah', 'Goat', 'Tiger']],
['1006', '2008-01-06T02:13:30Z', ['']],
['1007', '2008-01-06T02:13:38Z', ['Cheetah', 'Tiger', 'Goat']]]
I want create a new list of lists recording the first occurrence of each member with its ID. I want a list as follows:
output = [['1001', ''], ['1003', 'Lion'], ['1003', 'Rhinoceros'], ['1003', 'Leopard'],
['1003', 'Panda'], ['1004', 'Eagle'], ['1004', 'Tiger'], ['1005', 'Cheetah']
['1005', 'Goat']]
I tried the following code but it halts my computer and keeps running. I have to restart the computer to get it back to senses.
output= []
# Add the first id and member
for elements in node[0][2]:
output.append([node[0][0], elements])
for items in node[1:]:
for members in items[2]:
for root in output:
if member not in root:
output.append([items[0], member])
Appreciate any help and thanks in advance.