Three dumb questions (ordered by dumbness descending)
thorsten at thorstenkampe.de
Mon Sep 23 23:03:21 CEST 2002
Okay, here they are:
1. Why is 'zip(zip(x)) != x' (should be the same because it's the
2. Peter Norvig mentions in "Python for Lisp Programmers" some
"don'ts": "[x] + y" and "x[1:]". Are there more things to avoid
(especially in a loop)?
3. random.shuffle: the documentation says: "Note that for even rather
small len(x), the total number of permutations of x is larger than the
period of most random number generators; this implies that most
permutations of a long sequence can never be generated." I translate
this to "don't shuffle lists with more than 15 elements if you want a
randomly ordered list".
Alex Martelli says the same: "For example, Python users who are
calling random.shuffle on a sequence of substantial length have a need
for an underlying random generator with a *HUGE* period, as a
necessary although not sufficient condition towards ensuring that all
permutations of the shuffled sequence get generated with equal
Wichman-Hill has a period of less than 7,000 billions (7e12),
insufficient to account even for the permutations of a sequence
whose length is just 16 (16! > 2e13)."
Otherwise in the "Python Cookbook" (Selecting Random Elements from a
List Without Repetition) the shuffle version is called "the winner".
So: can I use random.shuffle or do I have to write my own - slower -
version to get a random list?
More information about the Python-list