mardi 23 juin 2020

How can I check if number exists in list

I wish to check if a certain number is in a list, but I'm struggling with the if sentence. I have

possibilities = []
node = 1
edges = [['1', '1', '10'], ['1', '6', '7'], ['1', '16', '5'], ['1', '18', '6'], ['1', '19', '6'], ['2', '2', '10'], ['2', '5', '3']]
for i in edges:
   if node in i[:-1]:
      possibilities.append(i)

print(possibilities)

But I'm not getting any entries in possibilities. Is there something I'm missing, because I thought this should work.

Aucun commentaire:

Enregistrer un commentaire