[Baypiggies] partial flattening of list

Julian Snitow jsnitow at gmail.com
Tue Jul 27 13:18:16 CEST 2010


On Mon, Jul 26, 2010 at 11:50 PM, Vikram <kpguy at rediffmail.com> wrote:

>
>
> have the following:
>
> >>> x
> [['NM100', 1, 2], ['NM100', 3, 4], ['NM200', 5, 6]]
> >>> for i in x:
> ... print i
> ...
> ['NM100', 1, 2]
> ['NM100', 3, 4]
> ['NM200', 5, 6]
>
> ------
> how does one obtain list z such that
>
> z = [['NM100',1,2,3,4],['NM200',5,6]]
>
>
>
Hint:   collections.defaultdict<http://docs.python.org/library/collections.html#collections.defaultdict>
(list) is your friend here.  The first
example<http://docs.python.org/library/collections.html#defaultdict-examples>
from
the docs is not far from your current problem. :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20100727/5eb1724b/attachment.html>


More information about the Baypiggies mailing list