lists to save in a tuple

Nader n.emami at gmail.com
Mon Jun 9 09:47:40 EDT 2008


On Jun 9, 3:34 pm, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
> Nader wrote:
> > Hello,
>
> > I have two lists and would save them in a tuple.
>
> > a = [1,2,3]
> > b = ['a','b','c']
>
> > with the next statement I can do that:
>
> > t = [(x,y), for x in a for y in b]
>
> > This gives the next list:
>
> > [(1,'a'),(1,'b'),(1,'c'), (2,'a'),(2,'b'),(2,'c'), (3,'a'),(3,'b'),
> > (3,'c')]
>
> > But I want the next list:
>
> > [(1,'a'),(2,'b'),(3,'c')]
>
> > Would somebody tell me how I can solve this problem?
>
> zip(a, b)
>
> Diez

Thank you!



More information about the Python-list mailing list