Random from Dictionary

Tim Payne doshea at mac.com
Thu Oct 18 09:04:50 EDT 2001


I've been browsing the message archives for some time looking for an
answer to this question, but I didn't find anything useful. Maybe you
guys could help me out.

I'm trying to obtain x number of random unique items from a
dictionary. This would have been easy to do with a list, but I need
the dictionary for other parts of the script.

I've tried popitem(), but arbitrary values just aren't good enough. I
need something that is random. Are there any other functions that I've
missed, or will I have to create my own? If so, any suggestions on a
clean way to do this? I've spent the better part of the morning trying
different ideas, but they were either too slow, or the code was a huge
mess by the time I was done. At one point, my function for random
values was larger than the program itself.

If you could just point me in the best direction to go, I'll probably
be able to figure out the rest on my own.

Thanks.



More information about the Python-list mailing list