User Guide

137
A dictionary is a special type of list. Instead of accessing the item
by its position in the list, you use a name. You create a dictionary
using curly braces. For example:
Beatles =
{"Lead":"John","Bass":"Paul","Drums":"Pete","Guitar:","Ge
orge"}
Each item is now made up of a pair of values – a key (the name),
and a value. To access the items in a dictionary, use the key
inside square brackets. For example:
Beatles["Drums"] = "Ringo"
The len() and del() functions work the same way for dictionaries
as they do for lists. And there are also several useful “methods”
that you access using a dot after the variable name.
insert(position, obj) Adds an item to the list in the specified position.
All list items that follow are moved down a
position.
remove(obj) Removes the specified item from the list. For
example: Beatles.remove("John").
reverse() Reverses the order of items in the list.
Method Description
clear() Removes all items from the dictionary.
copy() Returns a copy of the dictionary.
has_key(key) Returns True if the specified key is in the
dictionary, or False if it is not.
keys() Returns a list of the keys in the dictionary.
update(dic) Adds the items from the specified dictionary to
the current dictionary.
values() Returns a list of the values in the dictionary.
Method Description