create several lists with position

Issue

I have this super simple code to generate a list in python. I want to make several lists like this

0: [0, 2]
1: [2, 4]
2: [4, 6]

it is possible . thanks

n = range(0,169,2)
num_list=list(n)
print (num_list)

Solution

>>> {n: [n*2, n*2+2] for n in range(3)}
{0: [0, 2], 1: [2, 4], 2: [4, 6]}

Adjust the range(3) to produce however many lists you want.

If you want to be able to adjust the length of the individual lists:

>>> {n: list(range(n*2, n*2+4, 2)) for n in range(3)}
{0: [0, 2], 1: [2, 4], 2: [4, 6]}

Answered By – Samwise

Answer Checked By – Cary Denson (AngularFixing Admin)

Leave a Reply

Your email address will not be published.