Could someone explain how dictionaries are sorted and why? The below line's output:
>>> d= {(1, 2):"f", (1, 3):"f", (1, 4):"f", (1, 4):"f"}
>>> d
{(1, 2): 'f', (1, 5): 'f', (1, 3): 'f', (1, 4): 'f'}
and in general :
>>> de= {"a":1, "b":1, "c":1, "e":1, "d":1}
>>> de
{'a': 1, 'c': 1, 'b': 1, 'e': 1, 'd': 1}
Lists don't behave like this so I'm confused. This is more out of curiosity I could sort it myself for example.
They're hashtables, so they don't guarantee any sorting in any way. After all, that's why they're fast.