Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
In caseIf you also need the index:, use random.randrange
random.randrange
foo = ['a', 'b', 'c', 'd', 'e'] from random import randrange random_index = randrange(0,len(foo)) print (foo[random_index])
In case you also need the index:
foo = ['a', 'b', 'c', 'd', 'e'] from random import randrange random_index = randrange(0,len(foo)) print foo[random_index]
If you also need the index, use random.randrange
from random import randrange random_index = randrange(len(foo)) print(foo[random_index])
A more general approachIn case you also need the index:
A more general approach: