Showing results for 
Search instead for 
Did you mean: 
Pilot Lvl 1
Message 1 of 2

Python 3.7 dictionary confusion

Hey everyone

So i've been learning python from a coursera course and a book called "Python for everybody", however,I have some confusion regarding dictionaries 

In the videos I watch, it's said that dictionaries aren't ordered but I've read that since Python 3,7, they're ordered based on their insertion

The problem I have is with Tuples, for example, in of the exercises, we have :

>>> d = {'a':10, 'b':1, 'c':22}
>>> d.items()
dict_items([('a', 10), ('c', 22), ('b', 1)])
>>> sorted(d.items())
[('a', 10), ('b', 1), ('c', 22)]

However, when I use the d.items() , I get the a list with the correct order. 

So I was wondering if  the "sorted()" function is useful in dictionaries or not ? Because for example here I can use the "d.items()" and get the same result

Thanks !

1 Reply
Pilot Lvl 1
Message 2 of 2

Re: Python 3.7 dictionary confusion

Sorry I understand the difference now.