SlideShare a Scribd company logo
1 of 20
DICTIONARY
Class XI
CHAPTER-13
Dictionary
Dictionary
It is an unordered collection of items where each
item consist of a key and a value.
It is mutable (can modify its contents ) but Key must be
unique and immutable.
COMPUTERSCIENCE (CLASS XI)
Dictionary
Creating A Dictionary
• It is enclosed in curly braces {} and each item is separated
from other item by a comma(,)
• Within each item, key and value are separated by a colon (:)
• Passing value in dictionary at declaration is dictionary
initialization.
• get() method is used to access value of a key
E.g.
dict = {‘Subject': ‘Informatic Practices', 'Class': ‘11'}
Accessing List Item
dict = {'Subject': 'Informatics Practices', 'Class': 11}
print(dict)
print ("Subject : ", dict['Subject'])
dict.get('Class')
OUTPUT
{'Class': '11', 'Subject': 'Informatics Practices'}
('Subject : ', 'Informatics Practices')
11
Dictionary
Iterating / Traversing through A Dictionary
Following example will show how dictionary items can be accessed
through loop.
e.g.
dict = {'Subject': 'Informatics Practices', 'Class': 11}
for i in dict:
print(dict[i])
OUTPUT
Informatics Practices
11
Dictionary
Iterating / Traversing through A Dictionary
Following example will show how dictionary items can be accessed
through loop.
e.g.
dict = {'Subject': 'Informatics Practices', 'Class': 11}
for i in dict:
print(dict[i])
OUTPUT
Informatics Practices
11
Updating/Manipulating Dictionary Elements
We can change the individual element of
dictionary.
e.g.
dict = {'Subject': 'Informatics Practices', 'Class': 11}
dict['Subject']='computer science'
print(dict)
OUTPU
T
Dictionary
Questions
1. Create dictionary to store 4 student details
with rollno, name, age.
2. Create dictionary for month and no of days
for a year. User is asked to enter month
name and system will show no of days of
that month.
Dictionary
Visit : python.mykvs.in for regular
Deleting Dictionary Elements
del, pop() and clear() statement are used to remove
elements from the dictionary.
e.g. DEL
dict = {'Subject': 'Informatics Practices', 'Class': 11}
print('before del', dict)
del dict['Class'] # delete single element
print('after item delete', dict)
del dict #delete whole dictionary
print('after dictionary delete', type(dict))
Output
(before del {'Class': 11, 'Subject': 'Informatics Practices'})
(after item delete {'Subject': 'Informatics Practices'})
('after dictionary delete' <type 'dict'>)
Dictionary
pop() method is used to remove a particular item in a
dictionary.
clear() method is used to remove all elements from the dictionary.
e.g.
dict = {'Subject': 'Informatics Practices', 'Class': 11}
print('before del', dict)
dict.pop('Class')
print('after item delete', dict)
dict.clear()
print('after clear', dict)
Output
('before del' {'Class': 11, 'Subject': 'Informatics Practices'})
(after item delete {'Subject': 'Informatics Practices'})
('after clear' {})
Dictionary
Dictionary
MCQ
Q.1 What will be the output of the following?
d = {“abc”: 5, “def”: 6, “ghi”:7}
print(d1[“abc”]) # Line 1
print(d[0]) # Line 2
Q.2. Dictionaries are___________ data types of Python.
a) Mutable b)immutable c) simple d) none of these
Q.3. Which of the following can be used to delete item(s) from a
dictionary?
a) Del b) pop() c) popitem() d) all of these
Q.4. Dictionaries are also called_________
a) Mapping b) hashes c) associative arrays
d) all of these
Built-in Dictionary Functions
S.No. Function & Description
1 len(dict)----Gives the total length of the dictionary. It is equal to the
number of items in the dictionary.
dict = {'Name': 'Aman', 'Age': 37}
print (len (dict))
OUTPUT ->2
2 str(dict)-----Return a printable stringrepresentationof a Dictionary.
dict = {'Name': 'Aman', 'Age': 37}
>>> "{'Name': 'Aman', 'Age': 37}"
3 type(variable)If variable is dictionary, then it would return a
dictionary type.
dict = {'Name': 'Aman', 'Age': 37}
>>>type(dict)
Dictionary
Built-in Dictionary Methods
S.No. Method & Description
1 dict() - creates dictionary # Argument method
x = dict(name = “Aman", age = 37, country = “India")
Here x is created as dictionary
2
keys() - returns all the available keys
x = dict(name = “Aman", age = 37, country = “India")
print(x.keys())
OUTPUT->dict_keys(['country', 'age', 'name'])
3
values() - returns all the available values
x = dict(name = “Aman", age = 37, country = “India")
print(x.values())
OUTPUT->dict_values(['India', 37, 'Aman'])
Dictionary
S.No. Method & Description
4
items() - return the list with all dictionary keys with values.
x = dict(name = "Aman", age = 37, country = "India")
print(x.items())
OUTPUT->dict_items([('country', 'India'), ('age', 37), ('name',
'Aman')])
5
update()-used to change the values of a key and add new keys
x = dict(name = "Aman", age = 37, country =
India") d1 = dict(age= 39)
x.update(d1,state="Rajasthan
")
print(x)
OUTPUT-{'country': 'India', 'age': 39,'name':'Aman','state':
'Rajasthan'}
Dictionary
Built-in Dictionary Methods
S.No. Method & Description
6
del -used to remove key
x = dict(name = "Aman", age = 37, country = "India")
del x['age']
print(x)
OUTPUT->{'country': 'India', 'name': 'Aman'}
del x -> will remove complete dictionary
7
fromkeys() – is used to create dictionary from keys
keys = {'a', 'e', 'i', 'o', 'u' }
value ="Vowel"
vowels = dict.fromkeys(keys, value)
print(vowels)
OUTPUT-> {'i': 'Vowel', 'u': 'Vowel', 'e': 'Vowel', 'a': 'Vowel', 'o': 'Vowel'}
Dictionary
Built-in Dictionary Methods
S.No. Method & Description
8 copy() - returns a shallow copy of the dictionary.
x = dict(name = "Aman", age = 37, country = "India")
y=x.copy()
print(y)
print(id(x))
print(id(y))
OUTPUT - >{'country': 'India', 'age': 37, 'name': 'Aman'}
33047872
33047440
9 popitem() – removes last item from dictionary
x = dict(name = "Aman", age = 37, country = "India")
x.popitem()
print(x)
OUTPUT-> {'age': 37, 'name': 'Aman'}
Dictionary
Built-in Dictionary Methods
S.No. Method & Description
10 setdefault() method returns the value of the item with the specified
key. If the key does not exist, insert the key, with the specified value.
x = dict(name = "Aman", country = "India")
y=x.setdefault('age',39)
print(y)
OUTPUT->
39
11 max() – returns key having maximum value
Tv = {'a':100, 'b':1292, 'c' : 88}
Keymax = max(Tv, key=Tv.get)
print(Keymax)
OUTPUT-> b
12 min()- returns key having minimum value
Dict = {'Name': 'Aman', 'Age': 37}
print (min(Dict)
>>> Output - ?
Dictionary
Built-in Dictionary Methods
Dictionary
S.No. Method & Description
13 max( )- returns key having maximum value
Dict = {'Name': 'Aman', 'Age': 37}
print (max(Dict)
>>> Output - ?
14. sorted- sort by key or value
dict1 = {'b':100, 'a':12, 'c' : 88}
y = sorted(dict1.items(),key=lambda x:
x[1],reverse=True) print(y)
OUTPUT-> [('b', 100), ('c', 88), ('a',12)]
Dictionary
Built-in Dictionary Methods
Competency Based Question
stateCapital = {“AndhraPradesh”:”Hyderabad”, “Bihar”:”Patna”,
“Maharashtra”:”Mumbai”, “Rajasthan”:”Jaipur”}
Find output of the following:
1. print(stateCapital.get(“Bihar”))
2. print(stateCapital.keys()
3. print(stateCapital.values())
4. print(len(stateCapital))
5. del stateCapital [“Andhra Pradesh”]
print (stateCapital)
6. print(“Maharashtra” in stateCapital)
Dictionary
Visit : python.mykvs.in for regular
1. create a dictionary with names of
employees, their salary and access them
2. Count the number of times a character
appears in agiven string using a dictionary
Dictionary
Program:

More Related Content

Similar to dictionary14 ppt FINAL.pptx

beginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdfbeginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdf
ElNew2
 
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
Yashpatel821746
 

Similar to dictionary14 ppt FINAL.pptx (20)

Using-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptxUsing-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptx
 
The Ring programming language version 1.7 book - Part 37 of 196
The Ring programming language version 1.7 book - Part 37 of 196The Ring programming language version 1.7 book - Part 37 of 196
The Ring programming language version 1.7 book - Part 37 of 196
 
Ruby tricks2
Ruby tricks2Ruby tricks2
Ruby tricks2
 
2. Python Cheat Sheet.pdf
2. Python Cheat Sheet.pdf2. Python Cheat Sheet.pdf
2. Python Cheat Sheet.pdf
 
python cheat sheat, Data science, Machine learning
python cheat sheat, Data science, Machine learningpython cheat sheat, Data science, Machine learning
python cheat sheat, Data science, Machine learning
 
Beginner's Python Cheat Sheet
Beginner's Python Cheat SheetBeginner's Python Cheat Sheet
Beginner's Python Cheat Sheet
 
beginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdfbeginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdf
 
Farhana shaikh webinar_dictionaries
Farhana shaikh webinar_dictionariesFarhana shaikh webinar_dictionaries
Farhana shaikh webinar_dictionaries
 
Python : Functions
Python : FunctionsPython : Functions
Python : Functions
 
1. python
1. python1. python
1. python
 
Python cheatsheet for beginners
Python cheatsheet for beginnersPython cheatsheet for beginners
Python cheatsheet for beginners
 
Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge
 
Python dictionaries
Python dictionariesPython dictionaries
Python dictionaries
 
Python programming –part 7
Python programming –part 7Python programming –part 7
Python programming –part 7
 
The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196
 
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
 
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
 
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
 
Python data structures
Python data structuresPython data structures
Python data structures
 
اسلاید اول جلسه چهارم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه چهارم کلاس پایتون برای هکرهای قانونیاسلاید اول جلسه چهارم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه چهارم کلاس پایتون برای هکرهای قانونی
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 

dictionary14 ppt FINAL.pptx

  • 3. Dictionary It is an unordered collection of items where each item consist of a key and a value. It is mutable (can modify its contents ) but Key must be unique and immutable. COMPUTERSCIENCE (CLASS XI)
  • 5. Creating A Dictionary • It is enclosed in curly braces {} and each item is separated from other item by a comma(,) • Within each item, key and value are separated by a colon (:) • Passing value in dictionary at declaration is dictionary initialization. • get() method is used to access value of a key E.g. dict = {‘Subject': ‘Informatic Practices', 'Class': ‘11'} Accessing List Item dict = {'Subject': 'Informatics Practices', 'Class': 11} print(dict) print ("Subject : ", dict['Subject']) dict.get('Class') OUTPUT {'Class': '11', 'Subject': 'Informatics Practices'} ('Subject : ', 'Informatics Practices') 11 Dictionary
  • 6. Iterating / Traversing through A Dictionary Following example will show how dictionary items can be accessed through loop. e.g. dict = {'Subject': 'Informatics Practices', 'Class': 11} for i in dict: print(dict[i]) OUTPUT Informatics Practices 11 Dictionary
  • 7. Iterating / Traversing through A Dictionary Following example will show how dictionary items can be accessed through loop. e.g. dict = {'Subject': 'Informatics Practices', 'Class': 11} for i in dict: print(dict[i]) OUTPUT Informatics Practices 11 Updating/Manipulating Dictionary Elements We can change the individual element of dictionary. e.g. dict = {'Subject': 'Informatics Practices', 'Class': 11} dict['Subject']='computer science' print(dict) OUTPU T Dictionary
  • 8. Questions 1. Create dictionary to store 4 student details with rollno, name, age. 2. Create dictionary for month and no of days for a year. User is asked to enter month name and system will show no of days of that month. Dictionary Visit : python.mykvs.in for regular
  • 9. Deleting Dictionary Elements del, pop() and clear() statement are used to remove elements from the dictionary. e.g. DEL dict = {'Subject': 'Informatics Practices', 'Class': 11} print('before del', dict) del dict['Class'] # delete single element print('after item delete', dict) del dict #delete whole dictionary print('after dictionary delete', type(dict)) Output (before del {'Class': 11, 'Subject': 'Informatics Practices'}) (after item delete {'Subject': 'Informatics Practices'}) ('after dictionary delete' <type 'dict'>) Dictionary
  • 10. pop() method is used to remove a particular item in a dictionary. clear() method is used to remove all elements from the dictionary. e.g. dict = {'Subject': 'Informatics Practices', 'Class': 11} print('before del', dict) dict.pop('Class') print('after item delete', dict) dict.clear() print('after clear', dict) Output ('before del' {'Class': 11, 'Subject': 'Informatics Practices'}) (after item delete {'Subject': 'Informatics Practices'}) ('after clear' {}) Dictionary
  • 11. Dictionary MCQ Q.1 What will be the output of the following? d = {“abc”: 5, “def”: 6, “ghi”:7} print(d1[“abc”]) # Line 1 print(d[0]) # Line 2 Q.2. Dictionaries are___________ data types of Python. a) Mutable b)immutable c) simple d) none of these Q.3. Which of the following can be used to delete item(s) from a dictionary? a) Del b) pop() c) popitem() d) all of these Q.4. Dictionaries are also called_________ a) Mapping b) hashes c) associative arrays d) all of these
  • 12. Built-in Dictionary Functions S.No. Function & Description 1 len(dict)----Gives the total length of the dictionary. It is equal to the number of items in the dictionary. dict = {'Name': 'Aman', 'Age': 37} print (len (dict)) OUTPUT ->2 2 str(dict)-----Return a printable stringrepresentationof a Dictionary. dict = {'Name': 'Aman', 'Age': 37} >>> "{'Name': 'Aman', 'Age': 37}" 3 type(variable)If variable is dictionary, then it would return a dictionary type. dict = {'Name': 'Aman', 'Age': 37} >>>type(dict) Dictionary
  • 13. Built-in Dictionary Methods S.No. Method & Description 1 dict() - creates dictionary # Argument method x = dict(name = “Aman", age = 37, country = “India") Here x is created as dictionary 2 keys() - returns all the available keys x = dict(name = “Aman", age = 37, country = “India") print(x.keys()) OUTPUT->dict_keys(['country', 'age', 'name']) 3 values() - returns all the available values x = dict(name = “Aman", age = 37, country = “India") print(x.values()) OUTPUT->dict_values(['India', 37, 'Aman']) Dictionary
  • 14. S.No. Method & Description 4 items() - return the list with all dictionary keys with values. x = dict(name = "Aman", age = 37, country = "India") print(x.items()) OUTPUT->dict_items([('country', 'India'), ('age', 37), ('name', 'Aman')]) 5 update()-used to change the values of a key and add new keys x = dict(name = "Aman", age = 37, country = India") d1 = dict(age= 39) x.update(d1,state="Rajasthan ") print(x) OUTPUT-{'country': 'India', 'age': 39,'name':'Aman','state': 'Rajasthan'} Dictionary Built-in Dictionary Methods
  • 15. S.No. Method & Description 6 del -used to remove key x = dict(name = "Aman", age = 37, country = "India") del x['age'] print(x) OUTPUT->{'country': 'India', 'name': 'Aman'} del x -> will remove complete dictionary 7 fromkeys() – is used to create dictionary from keys keys = {'a', 'e', 'i', 'o', 'u' } value ="Vowel" vowels = dict.fromkeys(keys, value) print(vowels) OUTPUT-> {'i': 'Vowel', 'u': 'Vowel', 'e': 'Vowel', 'a': 'Vowel', 'o': 'Vowel'} Dictionary Built-in Dictionary Methods
  • 16. S.No. Method & Description 8 copy() - returns a shallow copy of the dictionary. x = dict(name = "Aman", age = 37, country = "India") y=x.copy() print(y) print(id(x)) print(id(y)) OUTPUT - >{'country': 'India', 'age': 37, 'name': 'Aman'} 33047872 33047440 9 popitem() – removes last item from dictionary x = dict(name = "Aman", age = 37, country = "India") x.popitem() print(x) OUTPUT-> {'age': 37, 'name': 'Aman'} Dictionary Built-in Dictionary Methods
  • 17. S.No. Method & Description 10 setdefault() method returns the value of the item with the specified key. If the key does not exist, insert the key, with the specified value. x = dict(name = "Aman", country = "India") y=x.setdefault('age',39) print(y) OUTPUT-> 39 11 max() – returns key having maximum value Tv = {'a':100, 'b':1292, 'c' : 88} Keymax = max(Tv, key=Tv.get) print(Keymax) OUTPUT-> b 12 min()- returns key having minimum value Dict = {'Name': 'Aman', 'Age': 37} print (min(Dict) >>> Output - ? Dictionary Built-in Dictionary Methods Dictionary
  • 18. S.No. Method & Description 13 max( )- returns key having maximum value Dict = {'Name': 'Aman', 'Age': 37} print (max(Dict) >>> Output - ? 14. sorted- sort by key or value dict1 = {'b':100, 'a':12, 'c' : 88} y = sorted(dict1.items(),key=lambda x: x[1],reverse=True) print(y) OUTPUT-> [('b', 100), ('c', 88), ('a',12)] Dictionary Built-in Dictionary Methods
  • 19. Competency Based Question stateCapital = {“AndhraPradesh”:”Hyderabad”, “Bihar”:”Patna”, “Maharashtra”:”Mumbai”, “Rajasthan”:”Jaipur”} Find output of the following: 1. print(stateCapital.get(“Bihar”)) 2. print(stateCapital.keys() 3. print(stateCapital.values()) 4. print(len(stateCapital)) 5. del stateCapital [“Andhra Pradesh”] print (stateCapital) 6. print(“Maharashtra” in stateCapital) Dictionary Visit : python.mykvs.in for regular
  • 20. 1. create a dictionary with names of employees, their salary and access them 2. Count the number of times a character appears in agiven string using a dictionary Dictionary Program: