[Tutor] A puzzle for you
Bob Gailer
bgailer at alum.rpi.edu
Sat Oct 14 19:28:27 CEST 2006
John Fouhy wrote:
> >From the python_dev LiveJournal community ---
>
> Predict the outcome of the following code:
>
> ##
> from random import *
> seed()
> [choice(dict((x+1,0) for x in range(1000))) for x in range(693)][0]
> ##
>
Hmm - interesting. Given that the argument of random.choice is supposed
to be a sequence (according to the docs str, unicode, list, tuple,
buffer, xrange), I'd expect an exception. I also predicted the the
result if no exception was raised, and that was correct.
I will withhold further observation until others (who wish) may reply.
--
Bob Gailer
510-978-4454
More information about the Tutor
mailing list