Looking at this snippet of python code I wrote:
return map(lambda x: x[1],
filter(lambda x: x[0] == 0b0000,
my_func(i)
)
)
(Hoping it's self-explanatory)
I'm wondering if python has a better way to do it?
I learned python several months ago, wrote a couple scripts, and haven't used it much since. It puts me in a weird spot for learning because I know enough to do what I want but don't have the newbie instinct to find the "proper" way. I'm hoping this question will put me back on course...
I think you want a list comprehension:
[x[1] for x in my_func(i) if x[0] == 0]
List comprehensions are an extremely common Python idiom.
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