-2

Say I have the following lists:

list_a = [1, 4, 7]
list_b = [(2, 3), (5, 6), (8, 9)]

How do I combine them so that it becomes

[(1, 2, 3), (4, 5, 6), (7, 8, 9)]
Ian Low
  • 399
  • 4
  • 14

2 Answers2

2

You can expand the tuple in the second zipped item to build a final tuple

list_a = [1, 4, 7]
list_b = [(2, 3), (5, 6), (8, 9)]

print([(a,*b) for a,b in zip(list_a, list_b)])

Output

[(1, 2, 3), (4, 5, 6), (7, 8, 9)]
tdelaney
  • 73,364
  • 6
  • 83
  • 116
0
list_a = [1, 4, 7]
list_b = [(2, 3), (5, 6), (8, 9)]
# FOR LIST_A TO B
    
for i in range(len(list_a)):
    a = list_a[i]
    test = list_b[i] + (a,)
    print(test)
Rebootsa
  • 1
  • 2