0

Here are my two versions of python:

$ python --version
#=> Python 2.7.6
$ python3 --version
#=> Python 3.4.3

And I have this code:

new_dict = { 'A': ['B', 'D'], 'B': ['A', 'D', 'C'], 'C': ['B'], 'D': ['A', 'B'], 'E' : [] }
print(new_dict)

And here is the output from running it a couple times

$ python3 test.py
#=> {'A': ['B', 'D'], 'E': [], 'B': ['A', 'D', 'C'], 'C': ['B'], 'D': ['A', 'B']}
$ python3 test.py
#=> {'B': ['A', 'D', 'C'], 'C': ['B'], 'E': [], 'D': ['A', 'B'], 'A': ['B', 'D']}
$ python3 test.py
#=> {'B': ['A', 'D', 'C'], 'A': ['B', 'D'], 'D': ['A', 'B'], 'C': ['B'], 'E': []}
$ python3 test.py
#=> {'C': ['B'], 'B': ['A', 'D', 'C'], 'E': [], 'A': ['B', 'D'], 'D': ['A', 'B']}

I don't understand why the dictionary is out of order when it's printed. Running it on Python 2.7.6 works fine:

$ python test.py
#=> {'A': ['B', 'D'], 'C': ['B'], 'B': ['A', 'D', 'C'], 'E': [], 'D': ['A', 'B']}
$ python test.py
#=> {'A': ['B', 'D'], 'C': ['B'], 'B': ['A', 'D', 'C'], 'E': [], 'D': ['A', 'B']}
$ python test.py
#=> {'A': ['B', 'D'], 'C': ['B'], 'B': ['A', 'D', 'C'], 'E': [], 'D': ['A', 'B']}
$ python test.py
#=> {'A': ['B', 'D'], 'C': ['B'], 'B': ['A', 'D', 'C'], 'E': [], 'D': ['A', 'B']}
DC00
  • 53
  • 6

0 Answers0