In Python, is there a way to retrieve the list of keys in the order in that the items were added?
String.compareMethods = {'equals': String.equals,
'contains': String.contains,
'startswith': String.startswith,
'endswith': String.endswith}
The keys you see here are meant for a select (dropdown) box so the order is important.
Is there a way without keeping a separate list (and without overcomplicating things for what I’m trying to do)? For what I see it’s not possible due to the hashing involved…
I’m using Python 2.6.x.
Use a
collections.OrderedDicton Python 2.7+, orOrderedDictfrom PyPI for older versions of Python. You should be able to install it for Python 2.4-2.6 withpip install ordereddictoreasy_install ordereddict.It is a subclass of
dict, so any method that takes adictwill also accept anOrderedDict.