4
I have this list called "brazil" and I wanted to understand why when I asked for it in Google Colab Notebook calling its respective variable, the list is presented in a certain order and when I print it out, it appears with dictionaries that are inside it in an inverted way. So my doubts are:
- This happens due to some update of Python 3.9 or something?
- How I check the version of Python running on Google Colab Research?
- Does it happen because of some optional sort parameter whose default value causes it? If not, what would happen?
- The same thing happened to someone else?
Caveats:
- Yes, I have tested this in other code editors including IDLE 3.8.3, so I should worry about updating Python and its respective IDLE to see if the problem persists?
- And to make it a little more explicit: testing in IDLE the result was as "expected", that is, the order of the dictionaries in the list was maintained after the variable call.
Follows the code:
estado1 = {'uf':'Rio de Janeiro', 'sigla':'RJ'}
estado2 = {'uf':'São Paulo', 'sigla':'SP'}
brasil = []
brasil.append(estado1)
brasil.append(estado2)
print(brasil) # A
brasil # B
--------------------
output:
[{'uf': 'Rio de Janeiro', 'sigla': 'RJ'}, {'uf': 'São Paulo', 'sigla': 'SP'}] # A
[{'sigla': 'RJ', 'uf': 'Rio de Janeiro'}, {'sigla': 'SP', 'uf': 'São Paulo'}] # B
The same goes for dictionaries alone:
In IDLE (the code is the same from above):
>>> estado1
{'uf': 'Rio de Janeiro', 'sigla': 'RJ'}
>>> estado2
{'uf': 'São Paulo', 'sigla': 'SP'}
>>> print(brasil)
[{'uf': 'Rio de Janeiro', 'sigla': 'RJ'}, {'uf': 'São Paulo', 'sigla': 'SP'}]
>>> brasil
[{'uf': 'Rio de Janeiro', 'sigla': 'RJ'}, {'uf': 'São Paulo', 'sigla': 'SP'}]
>>>
So this is basically my curiosity. I thank to whom to answer!