O'Reilly logo

Learn Python the Hard Way: A Very Simple Introduction to the Terrifyingly Beautiful World of Computers and Code, Third Edition, Video-Enhanced Edition by Zed A. Shaw

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exercise 39. Dictionaries, Oh Lovely Dictionaries

ImageVideo: Exercise 39: Dictionaries, Oh Lovely Dictionaries

Now I have to hurt you with another container you can use, because once you learn this container, a massive world of ultra-cool will be yours. It is the most useful container ever: the dictionary.

Python calls them “dicts.” Other languages call them “hashes.” I tend to use both names, but it doesn’t matter. What does matter is what they do when compared to lists. You see, a list lets you do this:

    >>> things = ['a', 'b', 'c', 'd']    >>> print things[1]    b    >>> things[1] = 'z'    >>> print things[1]    z ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required