Converting a tuple to a list

Brian breily at gmail.com
Wed Apr 9 00:36:18 CEST 2008


On Tue, Apr 8, 2008 at 6:22 PM, Steve Holden <steve at holdenweb.com> wrote:

> Gabriel Ibanez wrote:
> > Hi all ..
> >
> > I'm trying to using the map function to convert a tuple to a list,
> without
> > success.
> >
> > I would like to have a lonely line that performs the same as loop of the
> > next script:
> >
> > -------------------------------------------
> > # Conveting tuple -> list
> >
> > tupla = ((1,2), (3,4), (5,6))
> >
> > print tupla
> >
> > lista = []
> > for a in tupla:
> >     for b in a:
> >         lista.append(b)
> > print lista
> > -------------------------------------------
> >
> > Any idea ?
> >
> > Thanks ...
> >
> > # Gabriel
> >
> list(tupla)
>
> would probably do it.
>
> regards
>  Steve
> --
> Steve Holden        +1 571 484 6266   +1 800 494 3119
> Holden Web LLC              http://www.holdenweb.com/
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



That would just make a list of tuples, I think he wants [1, 2, 3, 4, 5, 6].

Try:  l = [x for z in t for x in z]

--Brian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080408/d142049b/attachment.html>


More information about the Python-list mailing list