[pyar] Lista agrupada

Ale peralta.alejandro en gmail.com
Vie Sep 23 18:34:20 ART 2011


Uh se me chispoteo el cut-n-paste, ahí está.

>
> Puedo dar mi versión, puedo, puedo??? :-P  Medio funcional...
>
> iIn [1]: import operator
>
> In [2]: igetter = operator.itemgetter(2)
>
> In [3]: mylist = [ ["auto", "DAL399", "alvarez"],  ["moto", "393DSR", "gomez"], ["auto", "SFT320", "perez"], ["auto", "DSL598", "gomez"]]
>
> In [4]: import itertools
>
> In [5]: for k, g in itertools.groupby(sorted(mylist, key=igetter), igetter): k, list(g)
>    ...:
> Out[9]: ('alvarez', [['auto', 'DAL399', 'alvarez']])
> Out[9]: ('gomez', [['moto', '393DSR', 'gomez'], ['auto', 'DSL598', 'gomez']])
> Out[9]: ('perez', [['auto', 'SFT320', 'perez']])
>
>
>
> --
> Ale.



--
Ale.



More information about the pyar mailing list