Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split #18

Closed
berrytj opened this issue Aug 14, 2014 · 6 comments
Closed

Split #18

berrytj opened this issue Aug 14, 2014 · 6 comments

Comments

@berrytj
Copy link

berrytj commented Aug 14, 2014

users_over_21, users_under_21 = split(lambda user: user.age >= 21, users)

thoughts? doing it manually is cumbersome, but maybe you have a better way.

over_21 = lambda user: user.age >= 21
users_over_21 = filter(over_21, users)
users_under_21 = filter(complement(over_21), users)

i'd be happy to implement.

@Suor
Copy link
Owner

Suor commented Aug 14, 2014

Funcy already has such function. And it's named split :)

@Suor Suor closed this as completed Aug 14, 2014
@Suor
Copy link
Owner

Suor commented Aug 14, 2014

You might also want to look at whatever. It could be used like this:

from funcy import split
from whatever import _

over, under = split(_.age >= 21, users)

@berrytj
Copy link
Author

berrytj commented Aug 14, 2014

Wow. I'm flabbergasted that I missed that. Sorry!

@berrytj
Copy link
Author

berrytj commented Aug 14, 2014

That's a good use case. I had been using the _ from fn.py -- curious if there are differences?

@Suor
Copy link
Owner

Suor commented Aug 14, 2014

whatever is faster, and it's small single purpose library.

@berrytj
Copy link
Author

berrytj commented Aug 14, 2014

Good to know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants