Sah_Boi_10
Sah_Boi_10

Reputation: 1

How do I add serial numbers to list elements?

There is a list:

L = [2, 3, 5, 7, 11]

Now I want to make this into a list of tuples like so:

L = [(1, 2), (2, 3), (3, 5), (4, 7), (5, 11)]

I do not want to do this manually because in my actual code, I intend on doing this with 10,000 prime numbers. How can I do this?

Upvotes: 0

Views: 672

Answers (1)

Wondercricket
Wondercricket

Reputation: 7872

You can use enumerate

L = [2,3,5,7,11]    
L = list(enumerate(L, 1))
print(L)
>>> [(1, 2), (2, 3), (3, 5), (4, 7), (5, 11)]

Upvotes: 3

Related Questions