mardi 26 avril 2016

Python 3 - creating list with randint [duplicate]

This question already has an answer here:

I have the following code:

import random

num_custs = int(input('custs '))
num_floors = int(input('floors '))

start = (random.randint(0, num_floors) for x in range(num_custs))
start = list(start)
print(start)
end = (random.randint(0, num_floors) for x in range(num_custs))
end = list(end)
print(end)

It outputs:

custs 10
floors 5
[5, 0, 0, 5, 1, 2, 2, 0, 3, 1]
[4, 1, 5, 1, 1, 1, 1, 3, 2, 0]

What I want is one list with the values from the first list mapped to the values from the second list like this:

[(5, 4), (0, 1), (0, 5), (5, 1)] etc.

I have been searching for this online for ages and can't seem to find what I am looking for.

Am I approaching this correctly or is there a better way?




Aucun commentaire:

Enregistrer un commentaire