[poll] anyone else needs fast random element access off a dictionary?

Michal Vitecek fuf at mageo.cz
Tue Feb 11 18:47:00 CET 2003


 hello Peter,

 there's nothing wrong with this approach of course. the only problem is
 that maintaing lists of keys, values or even items would be very
 expensive in case the keys would change very often.

Peter Hansen wrote:
>What is wrong with subclassing to create your own object, with
>the property of maintaining a list of the keys, or values, or both,
>and even a getRandomItem() method which does the above in a very
>speedy manner?
>
>That's what object-oriented programming is all about... in this
>case it lets you optimize for the frequent case, even though it
>might slow down other situations in a fairly minor way.
>
>-Peter
>-- 
>http://mail.python.org/mailman/listinfo/python-list

-- 
		fuf		(fuf at mageo.cz)





More information about the Python-list mailing list