When I practiced the questions in leetcode, I found that there are some differences between Py2 and Py3 in traversing a dictionary. For example, when I run the following codes in Py3, the key and values are printed out one by one as their sequence in the dict1, like (1, 2), (3, 5),(7, 8), (9, 6). However, when I run the same code in dict2, it prints (7, 8) , (1, 2) , (3, 5), (9, 6). Why does this happen? How to print it as their original sequence in Py2? Thanks
dict1 = {1:2, 3: 5, 9: 6, 7: 8}
for each in dict1:
print(each, dict1[each])