jeudi 23 septembre 2021

If else multiple tuples in a list

I am having an if method to check whether the [1] index value inside a tuple is less or equal to 255. While im feeding this method a single tuple inside a list it works eg [(0, 323)], but when im feeding the [(0, 323), (1, 1)] it doesn't.

if [i for i in a if i[1] <= 255]:
    print("a")
else:
    print("b")

Example if my values are [(0, 323)] it correctly prints b but when they change to a multiple tuple inside the same list [(0, 323), (1, 1)] it just prints a which is not correct. Any inputs please?

Aucun commentaire:

Enregistrer un commentaire