key - key pairs

sameer_deshpande sameer_deshpande at hotmail.com
Thu Jun 23 22:52:21 CEST 2005


Just an example of dictionary object in python.

PythonWin 2.4.1 (#65, Mar 30 2005, 09:33:37) [MSC v.1310 32 bit
(Intel)] on win32.
Portions Copyright 1994-2004 Mark Hammond (mhammond at skippinet.com.au) -
see 'Help/About PythonWin' for further copyright information.
>>> d = {}
>>> d["key1"] = "value1"
>>> d["key2"] = "value2"
>>> d["key3"] = "value3"
>>> d["key3"] = "value3"
>>>
>>> for i, j in d.items():
... 	print i, j
...
key3 value3
key2 value2
key1 value1
>>> if d.has_key("key1"):
... 	print d["key1"]
... else:
... 	print "no key"
...
value1
>>> if d.has_key("not in dict"):
... 	print d["key1"]
... else:
... 	print "no key"
... 
no key
>>> 

HTH

Sameer




More information about the Python-list mailing list