Created
August 2, 2012 13:06
-
-
Save Jim-Holmstroem/3236929 to your computer and use it in GitHub Desktop.
python groupby unsorted and loose the iterators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools as it | |
def sortandgroupby(data, **kwargs): | |
return dict(map(lambda(k,v):(k,list(v)),it.groupby(sorted(data,kwargs),kwargs))) | |
print sortandgroupby(range(30),lambda x:mod(x,3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment