lundi 6 avril 2020

python one liner with nested if/else conditions

Real python noob here, and I'm a bit puzzled by looking at the result of this nested if/else one-liner in python:

num_arr = [5, 10, 15]
result = [i**2 if i == 10 else i-5 if i < 7 else i+5 for i in num_arr]

result = [0, 100, 20]

Shouldn't the result be [0, 15, 20] since 10 is greater than 7?

Aucun commentaire:

Enregistrer un commentaire