[Tutor] questions about tuples

Ricardo Aráoz ricaraoz at gmail.com
Wed Sep 26 20:31:13 CEST 2007


Fangwen Lu wrote:
> Dear all-
>  
> 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?
>  
> Say a=(1,2,3), b=(4,3,2),c=(9,5,6). I want to get a tuple as ((1,2,3),
> (4,3,2),(9,5,6)).
>  
> If there are just 2 tuples, I can write x=a and then x=(x,b). But for 3
> tuples or more, I will get something like (((1,2,3), (4,3,2)),(9,5,6)).
>  
> Thanks.
>  
> Fangwen
> 

>>> a = (1,2,3)
>>> b = (4,5,6)
>>> c = (7,8,9)
>>> x = (a,b,c)
>>> x
((1, 2, 3), (4, 5, 6), (7, 8, 9))

Or :

>>> x = []
>>> x.append(a)
>>> x.append(b)
>>> x.append(c)
>>> tuple(x)
((1, 2, 3), (4, 5, 6), (7, 8, 9))

HTH




More information about the Tutor mailing list