130

The first examples that I googled didn't work. This should be trivial, right?

2
  • 5
    This was in my first hit: docs.python.org/library/random.html#module-random -- random.choice(seq)¶ Return a random element from the non-empty sequence seq. Commented Jun 29, 2009 at 14:52
  • 1
    Many times looking in the library can be more helpful. Getting the documentation for the random module would have worked. It does take some time to know where to look, but for anything involving "random" check the random module first. Commented Jun 29, 2009 at 15:18

2 Answers 2

253
import random

mylist=['Pinky', 'Blinky', 'Inky', 'Clyde']
random.choice (mylist)
Sign up to request clarification or add additional context in comments.

Comments

65
import random
random.choice([1, 2, 3])

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.