From b74d9cd3df1f97819747ec6402b62ac84aecedcf Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Fri, 26 Jun 2009 01:02:01 -0400 Subject: [PATCH] changed introductory text in #dictionaries --- native-datatypes.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native-datatypes.html b/native-datatypes.html index 502a16a..88865f7 100644 --- a/native-datatypes.html +++ b/native-datatypes.html @@ -446,12 +446,12 @@ IndexError: pop from empty list

Dictionaries

-

One of Python’s most important datatypes is the dictionary, which defines one-to-one relationships between keys and values. +

One of Python’s most important datatypes is the dictionary. A dictionary is an unordered set of key-value pairs. When you add a key to a dictionary, you must also add a value for that key. (You can always change the value later.) Python dictionaries are optimized for retrieving the value when you know the key, but not the other way around.

A dictionary in Python is like a hash in Perl 5. In Perl 5, variables that store hashes always start with a % character. In Python, variables can be named anything, and Python keeps track of the datatype internally.

Creating A Dictionary

-

Creating a dictionary is easy. The syntax is similar to sets, but instead of values, you have key-value pairs. Once you have a dictionary, you can look up values by their key. +

Creating a dictionary is easy. The syntax is similar to sets [FIXME link fails because section is not written yet], but instead of values, you have key-value pairs. Once you have a dictionary, you can look up values by their key.

 >>> a_dict = {'server':'db.diveintopython3.org', 'database':'mysql'}  
 >>> a_dict