I have three different if conditions and want to see which conditions are met.
I thought I could work this with an empty list and append 1 if the condition is met and 0 otherwise.
check_list = []
sample = [1,4,7]
fixed_number = 5
if sample[0] < fixed_number:
check_list.append(1)
else:
check_list.append(0)
if sample[1] < fixed_number:
check_list.append(1)
else:
check_list.append(0)
if sample[2] < fixed_number:
check_list.append(1)
else:
check_list.append(0)
check_list
desired output in this case:
[1,1,0]
How can I make this code short and pythonic?
thank you.
Aucun commentaire:
Enregistrer un commentaire