I know using for loops display the items in a list in order, but it only displays them at once.
e.g.:
>>> list = [1,2,3,4,5]
>>> for i in list:
... print(i)
...
1
2
3
4
5
Same if I do it with range and length, regarding indexes.
But what random.choice() does is taking a random item in the list and then printing it each time the function is called.
e.g.:
>>> from random import choice
>>> list = [1,2,3,4,5]
>>> print(choice(list))
1
>>> print(choice(list))
5
>>> print(choice(list))
4
Is there an equivalent to random.choice() but for printing the items in lists in order each time it is required?
Like:
>>> list = [1,2,3,4,5]
>>> print(function(list))
1
>>> print(function(list))
2
>>> print(function(list))
3
And so on.
Aucun commentaire:
Enregistrer un commentaire