Structuring Data
125
Sam likes the color Blue.
{'Harry': 'Orange', 'Sarah': 'Purple', 'Amy': 'Red'}
As you can see, a dictionary always has a key and value pair separated from each
other by a colon (:). Instead of using an index to access individual values, you use
the key. The special
keys
function lets you obtain a list of keys that you can
manipulate in various ways. For example, you can use the keys to perform itera-
tive processing of the data values that the dictionary contains.
Dictionaries are a bit like individual tables within a database. You can update, add,
and delete records to a dictionary as shown. The
update
function can overwrite or
add new entries to the dictionary.
Do'stlaringiz bilan baham: |