1

Let us consider

x = ['1', '2', '3', '4', '5']
y = ['a', 'b', 'c', 'd', 'e']

How do I get the required output z?

z = [('1', 'a') , ('b', '2') , ('c', '3') , ('d', '4') , ('e', '5')]
phihag
289k75 gold badges475 silver badges489 bronze badges
asked Mar 24, 2012 at 16:40
0

2 Answers 2

8

You're looking for zip:

>>> x = ['1', '2', '3', '4', '5'] 
>>> y = ['a', 'b', 'c', 'd', 'e']
>>> z = zip(x, y)
>>> z
[('1', 'a'), ('2', 'b'), ('3', 'c'), ('4', 'd'), ('5', 'e')]
answered Mar 24, 2012 at 16:42
Sign up to request clarification or add additional context in comments.

Comments

3

It's called zip:

z = zip(x, y)
answered Mar 24, 2012 at 16:42

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.