0
The operation consists of comparing two lists of strings, detecting which items are common and placing them in a certain order in a new list.
The closest I got was:
nova = []
lista = ['a', 'b', 'c', 'd', 'e']
coluna = ['a', '1', '2', '4', 'b', '2', '4', '5', '6', 'c', '3', '3', '3', 'd', '3', '3', 'e', '1']
The goal is, from the matching items, to copy them to the next, copy, and so on, to form a list like this:
nova = ['a', 'a', 'a', 'a', 'b', 'b', 'b', 'b', 'b', 'c', 'c', 'c', 'c', 'd','d', 'd', 'e', 'e']
That is, depending on the indexes that coincide between two lists, these will be copied until the next.
The closest I came to the answer was using a nested loop:
for item_lista in lista:
for item_coluna in coluna:
if(item_lista==item_coluna):
nova.append(item_lista)
else:
nova.append(item_coluna)
A list returns, but the wrong one I intended:
nova=['a',
'1',
'2',
'4',
'b',
'2',
'4',
'5',
'6',
'c',
'3',
'3',
'3',
'd',
'3',
'3',
'e',
'1',
'a',
'1',
'2',
'4',
'b',
'2',
'4',
'5',
'6',
'c',
'3',
'3',
'3',
'd',
'3',
'3',
'e',
'1',
'a',
'1',
'2',
'4',
'b',
'2',
'4',
'5',
'6',
'c',
'3',
'3',
'3',
'd',
'3',
'3',
'e',
'1',
'a',
'1',
'2',
'4',
'b',
'2',
'4',
'5',
'6',
'c',
'3',
'3',
'3',
'd',
'3',
'3',
'e',
'1',
'a',
'1',
'2',
'4',
'b',
'2',
'4',
'5',
'6',
'c',
'3',
'3',
'3',
'd',
'3',
'3',
'e',
'1']
The mandatory case solved my situation! Thank you very much!!!!
– Erich Mozart