I know very well how to select a random item from a list with random.choice(seq) but how do I know the index of that element?
random.choice(seq)
import random l = ['a','b','c','d','e'] i = random.choice(range(len(l))) print i, l[i]
How can I generate random integers between 0 and 9 (inclusive) in Python? For example, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Assume I have the following list: foo = ['a', 'b', 'c', 'd', 'e'] What is the simplest way to retrieve an item at random from this list?
I have a list of objects and I want to shuffle them. I thought I could use the random.shuffle method, but this seems to fail when the list is of objects. Is there a method for shuffling objects or …