How do I select a random element from an array in Python?

Question:

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

Asked By: Hanno Fietz

||

Answers:

import random
random.choice([1, 2, 3])
Answered By: Johan Kotlinski
import random
random.choice (mylist)
Answered By: eduffy
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.