How do I randomly select from a list in Python?

Posted by Liam Block on Stack Overflow See other posts from Stack Overflow or by Liam Block
Published on 2013-10-27T21:47:57Z Indexed on 2013/10/27 21:53 UTC
Read the original article Hit count: 235

Filed under:
|
|
|

Basically, I've got a homework task of programming a text based battle simulator in Python. Obviously I've gone with pokémon... I would like the enemy to be randomly selected, however I don't know how to randomly select from a list...

    foo = ['a', 'b', 'c', 'd', 'e']
    from random import choice
    print choice(foo)

This is what I've been told to try but I've got no modules or anything imported... How can I make this work, appreciated.

© Stack Overflow or respective owner

Related posts about python

Related posts about list