Creating a list with specific layout,section

Question:

I would like to create a program that as a result gives output that every even numbers from 0 to 100, including 0.

a = list(range(0, 101, 2))
print(a)

Output (even numbers)

[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100]

The main thing is to have it in pair, inside the the list.

[(0, ), (2, ), ... , (98, )]

Asked By: Vidar567

||

Answers:

What about

a = list((i,) for i in range(0, 101, 2))

Not sure it’s the most efficient way.

Answered By: Origine

You can use list comprehension as follows

[(i,) for i in range(0, 101, 2)]
Answered By: Tushar Koley
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.