I'm trying to complete a challenge where I have to generate two lists of random numbers, then pull the numbers the lists have in common into another list with no repeats. I've got something that works but I feel like it could be shorter. Is there a better way to assign a random range to the lists z and y? Is there a list comprehension that would work?
import random
from random import randrange
z = list(range(random.randrange(1,100,1)))
y = list(range(random.randrange(1,100,1)))
for i in range(len(z)):
z[i] = random.randint(1,1000)
for i in range(len(y)):
y[i] = random.randint(1,1000)
c = { item for item in z if (item in y)}
print(c)
Aucun commentaire:
Enregistrer un commentaire