When I want a random item of a list, I normally do:
import random
random.randint(0, len(array)-1)
(and then put that in as the index for the list - array[<codeabove>]
)
However, I was wondering if it was more efficient / better practise to do the following:
import random
random.randint(1, len(array)) -1
Does it make any difference to execution time, or is better practise in general to use one over the other?
Aucun commentaire:
Enregistrer un commentaire