>> d.popitem() Removes and returns an arbitrary (key, value) pair from d
>> If this isn't random enough, then you can generate a random number in
>> range(len(d))
Peter> Although this idea may suit the OP, "arbitrary" is most
Peter> definitely not "random".
Correct. The libr
Peter,
Agreed... which is why I said the 'random' module should be imported if
more randomness is required.
I only mentioned d.popitem() first in case Tores' application didn't
need a psuedo-random item and instead he was looking to pull any value
without randomness.
--
http://mail.python.org/m
[EMAIL PROTECTED] wrote:
From the Python 2.4 quickreference:
d.popitem() Removes and returns an arbitrary (key, value) pair from
d
If this isn't random enough, then you can generate a random number in
range(len(d))
Although this idea may suit the OP, "arbitrary" is
most definitely not "ran
Tony Meyer wrote:
How can I select a random entry from a dictionary, regardless of its
key-values?
a = random.choice(d.keys())
a, d[a]
Or even:
key, value = random.choice(d.items())
or:
value = random.choice(d.values())
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailm
import random
print d[d.keys()[int(random.random()*len(d.keys()))]]
HTH
-c
--
http://mail.python.org/mailman/listinfo/python-list
>From the Python 2.4 quickreference:
d.popitem() Removes and returns an arbitrary (key, value) pair from
d
If this isn't random enough, then you can generate a random number in
range(len(d))
--
http://mail.python.org/mailman/listinfo/python-list
> How can I select a random entry from a dictionary, regardless of its
> key-values?
>>> import random
>>> d = {1:'a', 2:'b', 3:'c'}
>>> a = random.choice(d.keys())
>>> a, d[a]
(2, 'b')
(etc)
=Tony.Meyer
--
http://mail.python.org/mailman/listinfo/python-list