r/Python • • Oct 13 '14

Python: rich iterator

I could not find a library to fit my needs, so I decided to write one.. (standard story)

Just in case I'm not good at searching: is there a library providing something like what I'm trying to do, so that I don't waste my time?

1 Upvotes

8 comments sorted by

View all comments

2

u/metaperl Oct 13 '14

is there a library providing something like what I'm trying to do, so that I don't waste my time?

Why did you write it and then ask?

This little library is targeted for people who think that x.filter(f).map(g) looks better than x = map(g, filter(f, x))

Well how about:

[g(y) for y in [x for x in coll if f(x)]]

Yes, I guess I like your dotted approach better. Easier to read from left to right for me.

7

u/Mecdemort Oct 13 '14

You could just do

[g(y) for y in x if f(y)]