Dictionary outputs are chaotic


#1

While doing the lesson Python: Student becomes the teacher - 4, which asked us to print the content of different dictionary I noticed the output was chaotic, but deterministic. After doing some research this seems to be intended behaviour (Extra link).

That’s all fun and all but I was wondering if it’s still possible to somehow retain the initial formatting of the code, or sort in some other way (in python 2.7) as both the ordered and keyed assignment of lists and dictionaries feel quite powerful.

My code

I understand that the answer might simply be that there is no such way within python, as python is not intended to be used as a database.

Thank you for your help, have a nice day!


#2

Python has collections, which contains an ordered dictionary type:

https://docs.python.org/2/library/collections.html

however, the question is, do you really need an ordered dictionary? The ordered dictionary means the order has to remember, which costs more memory. Is that really worth it?


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.