Home > Back-end >  Equalize the value of two lists and return one list in Python?
Equalize the value of two lists and return one list in Python?

Time:11-22

listA = []
a = [1, 2, 3]
b = [9, 8, 7]

I want to have the below list:

listA = [(1, 9), (2, 8), (3, 7)]

CodePudding user response:

You can do so using list and zip

a = [1, 2, 3] 
b = [9, 8, 7]

print(list(zip(a, b)))

# output 
[(1, 9), (2, 8), (3, 7)]

CodePudding user response:

a = [1, 2, 3] 
b = [9, 8, 7]
c= []
for i in range(a):
    int_no=(a[i],b[i])
    c.append(int_no)
print(c)
#output=[(1, 9), (2, 8), (3, 7)]
  • Related