|
|
|
|
|
by RHSeeger
4357 days ago
|
|
Admittedly, my thought would be to chain the calls, not nest them: alist = words.filter(lambda word: word.startswith('a')
.map(foo)
That being said, my Python is limited and I don't know it filter/map are available as methods of a list. At the end of the day, there are cases where list comprehensions are much cleaner/understandable... and cases where the reverse is true. |
|
They're not. Which is a shame in my opinion, because as you've written it you can clearly read the operations in the order they happen, ie. filter followed by map. Instead, you do have to do the second line of what blossoms wrote above.
And I don't think it's possible to write a list comprehension that reads in execution order, either :(