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)]

4

u/bm371613 Oct 13 '14

The reason I wrote this prototype and then asked is that it only took me a few hours. These hours made it more clear to me what exactly am I going to do, and made it easier to ask if there is something like that already, since I have something to show.