Converting a list of lists to a single list

steve at divillo.com steve at divillo.com
Wed Jul 24 14:11:54 EDT 2013


Wow, thanks everyone. Very helpful indeed!

On Tuesday, July 23, 2013 2:52:21 PM UTC-7, st... at divillo.com wrote:
> I think that itertools may be able to do what I want but I have not been able to figure out how.
> 
> 
> 
> I want to convert an arbitrary number of lists with an arbitrary number of elements in each list into a single list as follows.
> 
> 
> 
> Say I have three lists:
> 
> 
> 
> [[A0,A1,A2], [B0,B1,B2] [C0,C1,C2]]
> 
> 
> 
> I would like to convert those to a single list that looks like this:
> 
> 
> 
> [A0,B0,C0,C1,C2,B1,C0,C1,C2,B2,C0,C1,C2,A1,B0,C0,C1,C2,B1,C0,C1,C2,B2,C0,C1,C2,A2,B0,C0,C1,C2,B1,C0,C1,C2,B2,C0,C1,C2]
> 
> 
> 
> An easier way to visualize the pattern I want is as a tree.
> 
> 
> 
> A0
> 
> 	B0
> 
> 		C0
> 
> 		C1
> 
> 		C2
> 
> 	B1
> 
> 		C0
> 
> 		C1
> 
> 		C2
> 
> 	B2
> 
> 		C0
> 
> 		C1
> 
> 		C2
> 
> A1
> 
> 	B0
> 
> 		C0
> 
> 		C1
> 
> 		C2
> 
> 	B1
> 
> 		C0
> 
> 		C1
> 
> 		C2
> 
> 	B2
> 
> 		C0
> 
> 		C1
> 
> 		C2
> 
> A2
> 
> 	B0
> 
> 		C0
> 
> 		C1
> 
> 		C2
> 
> 	B1
> 
> 		C0
> 
> 		C1
> 
> 		C2
> 
> 	B2
> 
> 		C0
> 
> 		C1
> 
> 		C2




More information about the Python-list mailing list