You can try it like this:
a = [('FI', 'SE'), ('SE', 'DK'), ('DK', 'DE'), ('DE', 'PL'), ('PL', 'BY')]
b = [['NL', 'DK', 0], ['NL', 'DE', 0], ['NL', 'BE', 0], ['FI', 'SE', 0.054]]
search1, search2 = ('FI', 'SE')
for val1, val2, val3 in b:
if((val1, val2) == (search1, search2)):
print(val1, val2, val3) # FI SE 0.054
break
else: # caso nao haja break e porque nao foi encontrado
print('não foi encontrado')
DEMONSTRATION
If you want to locate all elements of a
in b
, can:
a = [('FI', 'SE'), ('SE', 'DK'), ('DK', 'DE'), ('DE', 'PL'), ('PL', 'BY')]
b = [['NL', 'DK', 0], ['NL', 'DE', 0], ['NL', 'BE', 0], ['DE', 'PL', 0], ['FI', 'SE', 0.054]]
founds = []
for val1, val2, val3 in b:
if((val1, val2) in a):
founds.append([val1, val2, val3])
print(founds) # [['DE', 'PL', 0], ['FI', 'SE', 0.054]]
DEMONSTRATION
Or:
a = [('FI', 'SE'), ('SE', 'DK'), ('DK', 'DE'), ('DE', 'PL'), ('PL', 'BY')]
b = [['NL', 'DK', 0], ['NL', 'DE', 0], ['NL', 'BE', 0], ['DE', 'PL', 0], ['FI', 'SE', 0.054]]
founds = [[v[0], v[1], v[2]] for v in b if (v[0], v[1]) in a]
print(founds) # [['DE', 'PL', 0], ['FI', 'SE', 0.054]]
Will the two lists always have the same amount of sublists? If a has a has 5 sublists then b also has? Or it may be different?
– Miguel
They can have different sizes @Miguel.
– Danilo
How is the search? Search for
(FI, SE)
that’s it?– Miguel
Exactly @Miguel! I look for (FI, SE), but the return will be ['FI', 'SE', 0.054], as in b.
– Danilo