0

So have just started dictionaries in Python (using Spyder if that helps)... basically made a dictionary called t, but the values don't get stored in the order i have assigned

t={'first':'a','second':'b','third':'c'}
print t
for i in t :
    print t[i]

the values in t get stored as {'second': 'b', 'third': 'c', 'first': 'a'} and get assigned as such?! whats going on here?

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
Mukul Bhaskar
  • 11
  • 1
  • 4
  • 2
    Dictionaries are unordered until CPython 3.6 began maintaining insertion order as an implementation detail and Python 3.7+ added it as a formal specification. What version of Python are you using? – Mark Tolonen Apr 26 '20 at 13:54
  • 1
    looks like python 2 by the looks of the print statement without ( ) - – Patrick Artner Apr 26 '20 at 13:56
  • You can verify by using the answer of https://stackoverflow.com/questions/1252163/printing-python-version-in-output – Patrick Artner Apr 26 '20 at 13:58
  • the version im using is 2.7.17.. should i upgrade to python 3.7.. am not a power user just want to learn the language – Mukul Bhaskar Apr 26 '20 at 14:04

0 Answers0