+ 2

Else Break

Is there a way I can use else break in a comprehension? https://code.sololearn.com/chz1sErLj2VV/?ref=app

4th Jun 2020, 1:36 PM
Tomiwa Joseph
Tomiwa Joseph - avatar
3 Antworten
+ 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)])
5th Jun 2020, 6:45 PM
Tomiwa Joseph
Tomiwa Joseph - avatar
0
List comprehension don't support "else", only "if" statment.
5th Jun 2020, 6:16 PM
Leonid Selivanov
Leonid Selivanov - avatar
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.
5th Jun 2020, 6:55 PM
Leonid Selivanov
Leonid Selivanov - avatar