Can I expect the keys() to remain in the same order?
I plan to use them for a dropdown box and I dont want them to shift if I add or delete items from the dictionary.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The ordered of the keys in a
dictis not guaranteed.The documentation says:
Python 2.7+ and 3.1+ have the
OrderedDictclass incollectionsas described by PEP 372, which does exactly what you want. It remembers the order in which keys were added: