I would like to either extend or append a list to the content of another list:
I’ve got the following:
l = (('AA', 1.11,'DD',1.2), ('BB', 2.22, 'EE', 2.3), ('CC', 3.33, 'FF', 3.45))
ls = [('XX', 7.77), ('YY', 8.88), ('ZZ', 9.99)]
m = ['first', 'second', 'third']
for i in range(len(l)):
result = []
for n in m:
if n == "first":
r=[]
for word, number in ls[i]:
temp = [word, number]
r.append(temp)
for t in r:
result.extend(t)
print result
I would like to see the following result when the ‘result’ is printed out in the above code (each in newline):
['AA', 1.11, 'XX', 7.77]
['BB', 2.22, 'YY', 8.88]
['CC', 3.33, 'ZZ', 9.99]
Many thanks in advance.
All you need is zip: