Coding Nested Loops
Dan Sommers
me at privacy.net
Sat Sep 16 12:22:46 EDT 2006
On Sat, 16 Sep 2006 08:29:26 -0700 (PDT),
Rich Shepard <rshepard at appl-ecosys.com> wrote:
> Two questions germane to random: 1) Why wasn't choice available when
> I used 'import random,' ...
When you import random, all you're doing is importing the module; you
have to specify any given attribute thereof:
import random
random.choice( [ 1, 5, 7 ] )
> ... 2) What are the differences between 'choice' and 'shuffle?'
choice chooses one element of a given list and leaves the list itself
alone; shuffle shuffles the list, presumably so that you can iterate
through the elements yourself.
HTH,
Dan
--
Dan Sommers
<http://www.tombstonezero.net/dan/>
"I wish people would die in alphabetical order." -- My wife, the genealogist
More information about the Python-list
mailing list