lundi 30 décembre 2019

for loop and multiple if statements in one line?

Is there a way to write something like this in one line?

For x in list: 
   if condition1: 
       (...) 
   elif condition2: 
       (...) 
   else: 
       (...) 

Another way of asking is, is it possible to combine following list comprehensions?

(...) for x in list and,

123 if condition1 else 345 if condition2 else 0

Aucun commentaire:

Enregistrer un commentaire