Single line for loop over iterator with an “if” filter?

前端 未结 8 593
清歌不尽
清歌不尽 2020-12-13 12:55

Silly question:
I have a simple for loop followed by a simple if statement:

for airport in airports:
    if airport.is_important:

and

8条回答
  •  时光说笑
    2020-12-13 13:17

    This is a design philosophy of python. If it takes you too many words to put it on one line, it should be broken into a few lines to help the person who comes after you. List and generator expressions are more for transforming iterables in-place -- making more readable forms of map and filter.

提交回复
热议问题