Here a generic Python question about generators/list comprehension.
For a given iterable x
I need a list comprehension which looks like this:
[ flatten(e) for e in x if flatten(e) != '' ]
The function flatten
is potentially expensive, so it would be nice to call it only once. Is there a way to do this in an expressive one-liner?
Nest a generator:
[item for item in (flatten(e) for e in x) if item != '']
Or:
[item for item in map(flatten, x) if item != '']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With