[Tutor] questions about tuples

Alan Gauld alan.gauld at btinternet.com
Sun Sep 30 17:00:51 CEST 2007

"Fangwen Lu" <lufangwen at gmail.com> wrote

> I want to do some loops. Each loop will generate a tuple. Eventually 
> I want
> to put tuples together in a higher level of tuple. Do you know how 
> to do
> this?

Inaddition to other replies, you might be able to use a
generator expression to do it in one line:

>>> tuple( ( (x,x+1) for x in range(3) ) )
((0, 1), (1, 2), (2, 3))


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list