I want to either expand or attach a list to the contents of another list: I've got the following: < / P>
l = (('AA', 1.11, 'DD', 1.2), ('BB', 2.22, 'E', 2.3), ('CC', 3.33, 'FF ',' 3.4 '), ls = [(' xx ', 7.77), (' yy ', 8.88), (' zz ', 9.99)] = [' first ',' second ',' third '] in range For (Len (l)): result = [] in M n: if n == "first": for the word r = [], the number in ls [i]: temp = [word, number] r.append (Temp) for R in T: result.extend (t) print result I The 'results' is displayed in the code above (in each new line): '' AA ',' 1.1 ',' xx ', 7.77] [' BB ',' '' 2.22, 'YY', 8.88] ['CC', 3.33, 'ZZ', 9.99]
Many thanks in advance.
All you need is:
l = ((' AA ', 1.11), (' bb ', 2.22), (' cc ', 3.33)) ls = [(' xx ', 7.77), (' yy ', 8.88), (' zz ', 9.99]] X, for y in zip (L, LS): print (list (x + y)) # ['AA', 1.1, 100000000000001, 'xx', 7.7699999999999996] # ['BB', 2.2200000000000002, 'YY', 8.8800000000000008 ] # ['CC', 3.3300000000000001, 'ZZ', 9.99, 00000000000002]
Comments
Post a Comment