gaudetteje@gmai l.com wrote:[color=blue][color=green]
>>From the Python 2.4 quickreference:[/color]
>
> 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))[/color]
Although this idea may suit the OP, "arbitrary" is
most definitely not "random". Given the same
dictionary on two separate occasions, this approach
results in precisely the same sequence of items
being returned.
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.
>> d.popitem() Removes and returns an arbitrary (key, value) pair from d
[color=blue][color=green]
>> If this isn't random enough, then you can generate a random number in
>> range(len(d))[/color][/color]
Peter> Although this idea may suit the OP, "arbitrary" is most
Peter> definitely not "random".
Correct. The library reference is pretty clear about this too:
Keys and values are listed in an arbitrary order which is non-random,
varies across Python implementations , and depends on the dictionary's
history of insertions and deletions.
Comment