Creating a dictionary

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Oct 9 09:00:46 EDT 2012


On Tue, 09 Oct 2012 04:59:49 -0700, argbsk wrote:

> below is the text file i have How to create Facility as a key and then
> assign multiple values to it

To use Facility as a key in a dict:

d = {}
d['Facility'] = 'ham'

Note that keys are case-sensitive, so that 'Facility', 'facility', 
'FACILITY' and 'FaCiLiTy' are all different.

To have multiple values assigned to a key, use a list:

d['Facility'] = ['ham', 'spam', 'cheese', 'eggs']
d['Facility'].append('tomato')



-- 
Steven



More information about the Python-list mailing list