Let's say I want to random number, but the number cannot be i, or number that is already in the list. How can I check against my list in the if statement?
I think I'm close to the answer:
if randlink == i or (randlink == x for x in listofnumbers):
return randNumber(i, listofnumbers)
This function returns a number that did not appear before, this is the code:
def randNumber(i, listofnumbers):
from random import randrange
randlink = randrange(0, size)
if randlink == i or [randlink == x for x in listofnumbers]:
return randNumber(i, listofnumbers)
return randlink
Aucun commentaire:
Enregistrer un commentaire