Friday, 15 May 2015

python - How to concatenate nested lists together into a new nested list using a loop? -


I do not seem to understand how this can be done ... I have an example that gives me the result May be, but I can not understand how to do it with a loop.

  celts = [["bass", 1,2,3], ["Bradley", 7,8 [9]] celts2 = [["bass", 4,5,6 ], ["Bradley", 1,2,3]] Celts 3 = [["Bass", 8, 5, 2], ["Bradley", 7,4,1]] new = Selts [0] + Celts 2 [0] + Celts 3 [0], Selats [1] + Selset 2 [1] + Selseet 3 [1], New Print  

Result:

< ('Bass', 1, 2, 3, 'bass', 4, 5, 6, 'bass', 8, 5, 2], ['Bradley', 7, 8, 9, Bradley ', 1, 2, 3,' Bradley ', 7, 4, 1])

Using the understanding of the list (which is is a type of loop):

  celts = [["", 1,2,3], ["Bradley", 7, 8, 9]] Celts 2 = [["Bass", 4,5,6], ["Bradley", 1 , 2,3]] cells 3 = [["bass", 8, 5, 2], ["Bradley", 7,4,1] new = [Selats [i] + Celts 2 [i] + Selats 3 [ I] for the range (lanes (celtts))]> gt; & Gt; & Gt; Print 7, 8, 9, 'Bradley', ['Bass', 1, 2, 3, 'bass', 4, 5, 6, 'bass', 8, 5, 2], ['Bradley'] , 2, 3, 'Bradley', 7, 4, 1]]  

No comments:

Post a Comment