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

Michal Vitecek fuf at mageo.cz
Wed Feb 12 03:35:24 EST 2003


 after rereading it again i found the trick - yup - it seems like a good
 solution. thanks Dan!

>Dan Schmidt wrote:
>>Yeah, but you can update the list in O(1) time, rather than calling
>>keys() every time the dict changes.
>>
>>The dictionary is a mapping of key to a (value, list index) tuple,
>>where the list index is where that key is stored in the parallel list.
>>
>>When you delete a key, you look up the appropriate list index, swap
>>the last element into it, and update the previously last element's
>>list index in the dict.
>>
>>Dan

-- 
		fuf		(fuf at mageo.cz)





More information about the Python-list mailing list