Iterating Over Dictionary From Arbitrary Location

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Sat Jun 6 12:06:26 EDT 2009


akindo:
> So, it seems I want the best of both worlds: specific indexing using  
> my own IDs/keys (not just by list element location), sorting and the  
> ability to start iterating from a specific location.

A sorted associative map may be fit. A data structure based on a
search tree, like a red-black tree, etc.
The Python std lib doesn't contain such data structure.
Do you need to add items to your data structure? Diez has suggested a
possible solution. You can keep a copy of the items in a sorted list,
but this isn't handy if you have to add and remove items frequently.
Or you may be able to find somewhere a sorted associative array data
structure (tree-based).

Bye,
bearophile



More information about the Python-list mailing list