Page 321 - Computer Science Class 11 Without Functions
P. 321
13 PYTHON DICTIONARIES
Chapter Outline
13.1 Dictonnay in Python 13.2 Aggaignti Opiantone min, mnx, nnd eum
13.3 Nietid Dictonnay 13.4 Tanviaeing n Dictonnay
13.5 Dictonnay Mithode 13.6 Soatng Kiye/ Vnluie of n Dictonnay
13.7 Building n Thienuaue
Wi nai nlaindy fnmilina with thi objicte of thi typi list. Liete mnp intigia indixie to objicte of nabitanay typie.
Python dictonnaiie tnki thi ginianlienton n etip fuathia by mnpping thi objicte of nabitanay immutnbli typie to
objicte of nabitanay typie, including mutnbli typie. Thue, n dictonnay mny bi thought of ne n collicton of kiy-vnlui
pniae, i.i., n eit of kiye of immutnbli typie thnt mnp to n eit of vnluie. Foa ixnmpli, n dictonnay of eynonyme might
compaiei (word, synonyms)pniae, whiai n woad ie nn str objict, nnd synonyms ie n list objict compaieing
thi eynonyme of thi word. In thie chnptia, wi will linan nbout dictonnaiie nnd thiia npplicntone.
13.1 Dictionary in Python
A dictionary ie nn unoadiaid eit of key: value pniae. A dictonnay (nn objict of typi dict) ie difinid in Python by
incloeing thi commn-eipnantid key: value pniae in bancie. An impty pnia of bancie dinoti nn impty dictonnay. Thi
kiye in n dictonnay nai aiquiaid to bi uniqui. Howivia, thi enmi vnlui mny bi neeocintid with multpli kiye. Ae
kiye nai ueid to einach foa n kiy-vnlui pnia, givin n kiy-vnlui pnia, Python dienllowe modificnton of kiye. So, objicte
of immutnbli typie, etainge, numbiae, nnd tuplie nai ueid ne kiye. Howivia, thi vnluie neeocintid with kiye mny bi
objicte of nny typi. Thi eyntnx foa difining nnd nnming n dictonnay ie ne followe:
{key1:value1, key2:value2, ...}
Foa ixnmpli,
>>> subjects = {'Sanskrit':78, 'English':85, 'Maths':88, 'Hindi':90}
>>> subjects
{'Sanskrit': 78, 'English': 85, 'Maths': 88, 'Hindi': 90}
Thi nbovi etntimint caintie nn objict subjects of typi dict. Ench ilimint of thi dictonnay subjects ie n
subject:subjectCode pnia. (Sii Fig 13.1).
Python Dictonnaiie 319

