0

Why is the dictionary not in the same order that the key:value pairs were added?

def main():
    dictionary = {}
    names = ['a', 'd', 'g', 's', 'b', 'm', 'f', 'p']
    moves = [1,2,3,4,5,6,7,8]
    for k in range(len(names)):
        dictionary[names[k]] = moves[k]
        print player_dictionary
        print "\n"

main()
  • 1
    Because dictionaries aren't ordered in the first place. They are just mappings. – Blender May 01 '13 at 04:17
  • . .here is a pycon video(topic "The Mighty Dictionary").. http://blip.tv/pycon-us-videos-2009-2010-2011/pycon-2010-the-mighty-dictionary-55-3352147 .. .this video has a live example of why and how it is happening so – namit May 01 '13 at 04:19

0 Answers0