user18867040
user18867040

Reputation:

How to display two lists at the same time

I have two lists

x = ['34', '22', '45']
y = ['red', 'blue', 'grean']

I need to output these two lists together

34, red
22, blue
45, grean

i tried to get it all through for in

for a, b in x, y:
    print(a, b)

but i get an error

too many values to unpack (expected 2)

Upvotes: 0

Views: 71

Answers (2)

L8R
L8R

Reputation: 431

Try this:

x = ['34', '22', '45']
y = ['red', 'blue', 'green'] // you made a typo in 'green' so i fixed it
for i, x in enumerate(x):
    print(f"{x}, {y[i]}")

It returns this:

34, red
22, blue
45, green

Upvotes: 0

Aram SEMO
Aram SEMO

Reputation: 166

x = ['34', '22', '45']
y = ['red', 'blue', 'grean']

for a, b in zip(x, y):
    print(f"{a}, {b}")

Output:

34, red
22, blue
45, grean

Upvotes: 1

Related Questions