+ 2
Else Break
Is there a way I can use else break in a comprehension? https://code.sololearn.com/chz1sErLj2VV/?ref=app
6 Answers
+ 1
Leonid Selivanov but it does...just not the break statement. Check this out:
print([i if i%2==0 else i+15 for i in range(5)])
0
List comprehension don't support "else", only "if" statment.
0
Tomiwa Joseph I thought I read about it somewhere. Maybe I got confused with the lambda function or the information was not up to date. Need to experiment.