Silly question:
I have a simple for loop followed by a simple if statement:
for airport in airports:
if airport.is_important:
and I was wondering if I can write this as a single line somehow.
So, yes, I can do this:
for airport in (airport for airport in airports if airport.is_important):
but it reads so silly and redundant (for airport in airport for airport in airports...
).
Is there a better way?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…