SlideShare uma empresa Scribd logo
1 de 44
CHAPTER 16
DICTIONARIES
Unit 2:
Computational Thinking and Programming
XI
Computer Science (083)
Board : CBSE
Courtesy CBSE
Unit II
Computational Thinking and Programming
(60 Theory periods + 45 Practical Periods)
DCSc & Engg, PGDCA,ADCA,MCA.MSc(IT),Mtech(IT),MPhil (Comp. Sci)
Department of Computer Science, Sainik School Amaravathinagar
Cell No: 9431453730
Praveen M Jigajinni
Prepared by
Courtesy CBSE
LEARNING OUTCOMES
After studying this lesson, students
will be able to:
 Understand the need of dictionaries;
Solve problems by using dictionaries;
Get clear idea about dictionaries functions;
and
 Understand the difference between list and
dictionary.
LEARNING OUTCOMES
WHAT IS DICTIONARY?
A dictionary is like a list, but more in
general. In a list, index value is an integer, while
in a dictionary index value can be any other data
type and are called keys. The key will be used as
a string as it is easy to recall. A dictionary is an
extremely useful data storage construct for
storing and retrieving all key value pairs, where
each element is accessed (or indexed) by a
unique key. However, dictionary keys are not in
sequences and hence maintain no left-to right
order.
WHAT IS DICTIONARY?
We can refer to a dictionary as a
mapping between a set of indices (which
are called keys) and a set of values. Each
key maps a value. The association of a key
and a value is called a key-value pair.
Syntax:
my_dict = {'key1': 'value1','key2':
'value2','key3': 'value3'…'keyn': 'valuen'}
KEY VALYE PAIR
Curley brackets are used to represent a
dictionary.
Each pair in the dictionary is
represented by a key and value separated by a
colon.
Multiple pairs are separated by vcomas
DICTIONARIES
A dictionary is an unordered collection of key-
value pairs.
A dictionary has a length, specifically the numb
er of keyvalue pairs.
A dictionary provides fast look up by key.
The keys must be immutable object types.
DICTIONARIES
>>> A={1:"one",2:"two",3:"three"}
STATE DIAGRAM
A =
1 one
2 two
3 three
KEYS VALUES
CREATING A DICTIONARY – dict()
CREATING DICTIONARAY – dict()
The function dict ( ) is used to create a
new dictionary with no items. This function is
called built-in function. We can also create
dictionary using {}.
CREATING DICTIONARAY – Example
CREATING AND TRAVERSING DICTIONARAY
CREATING AND TRAVERSING DICTIONARAY
OUT PUT
CREATING AND TRAVERSING DICTIONARAY
OUT PUT
DICTIONARAY – BUILT IN METHODS
DICTIONARAY – BUILT IN METHODS
Dictionary Method Meaning
dict.clear() Removes all the elements of the
dictionary
dict.copy() Returns (shallow)copy of
dictionary.
dict.get(key,
default=None)
for key key, returns value or
default if key not in dictionary
(note that default's default is
None)
dict.items() returns a list of dict's (key, value)
tuple pairs
Dictionary Method Meaning
dict.keys() returns list of dictionary dict's
keys
dict.setdefault key,
default=None
similar to get(), but will set
dict[key]=default if key is not
already in dict
dict.update(dict2) adds dictionary dict2's key-values
pairs to dict
dict.values() returns list of dictionary dict's
values
DICTIONARAY – BUILT IN METHODS
Dictionary Method Meaning
dict.pop() returns list of dictionary dict's
keys
dict.popitem() similar to get(), but will set
dict[key]=default if key is not
already in dict
DICTIONARAY – BUILT IN METHODS
dict.clear() METHOD
clear method
OUTPUT is in next slide!
dict.clear() METHOD - OUTPUT
Birthday dictionary cleared
dict.copy() METHOD
copy method
OUTPUT is in next slide!
dict.copy() METHOD - OUTPUT
copy method creates b2 dictionary
dict.get() METHOD
OUTPUT is in next slide!
get method
dict.get() METHOD - OUTPUT
Creating a b2 dictionary using get method
dict.items() METHOD
OUTPUT is in next slide!
items method
dict.items() METHOD - OUTPUT
items method returns dictionary content
dict.keys() METHOD
OUTPUT is in next slide!
keys method
dict.keys() METHOD - OUTPUT
keys method returns dictionary keys
dict.update() METHOD
update method
dict.values() METHOD
values method returns dictionary values
dict.pop() METHOD
pop method removes specified key
values from the dictionary
dict.popitem() METHOD
popitem method removes values/items
from the dictionary
CLASS WORK/HOME WORK
CLASS WORK/HOME WORK
1. Write a Python script to sort (ascending and
descending) a dictionary by value.
2. Write a Python script to add a key to a dictionary.
Sample Dictionary : {0: 10, 1: 20}
Expected Result : {0: 10, 1: 20, 2: 30}
3. Write a Python script to concatenate following
dictionaries to create a new one.
Sample Dictionary :
dic1={1:10, 2:20}
dic2={3:30, 4:40}
dic3={5:50,6:60}
Expected Result : {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6:
60}
CLASS WORK/HOME WORK
4. Write a Python script to check if a given key
already exists in a dictionary.
5. Write a Python program to iterate over
dictionaries using for loops.
6. Write a Python script to generate and print a
dictionary that contains a number (between 1 and
n) in the form (x, x*x).
Sample Dictionary ( n = 5) :
Expected Output : {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
CLASS WORK/HOME WORK
7. Write a Python script to print a dictionary where
the keys are numbers between 1 and 15 (both
included) and the values are square of keys.
Sample Dictionary
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81,
10: 100, 11: 121, 12: 144, 13: 169, 14: 196, 15: 225}
8. Write a Python script to merge two Python
dictionaries.
CLASS WORK/HOME WORK
9. Write a Python program to iterate over
dictionaries using for loops.
10. Write a Python program to sum all the items in
a dictionary.
Class Test
Class Test
Class Test
Time: 40 Min Max Marks: 20
1. What is dictionary? give example 02
2. Write a python script to traverse a
dictionary 05
3. Explain 5 list built in methods of
dictionary 10
4. What is key value pair? Explain 05
Thank You

Mais conteúdo relacionado

Mais procurados

Python Programming - XI. String Manipulation and Regular Expressions
Python Programming - XI. String Manipulation and Regular ExpressionsPython Programming - XI. String Manipulation and Regular Expressions
Python Programming - XI. String Manipulation and Regular Expressions
Ranel Padon
 

Mais procurados (20)

Python list
Python listPython list
Python list
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
 
List in Python
List in PythonList in Python
List in Python
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Chapter 03 python libraries
Chapter 03 python librariesChapter 03 python libraries
Chapter 03 python libraries
 
stack & queue
stack & queuestack & queue
stack & queue
 
Python revision tour i
Python revision tour iPython revision tour i
Python revision tour i
 
Lesson 02 python keywords and identifiers
Lesson 02   python keywords and identifiersLesson 02   python keywords and identifiers
Lesson 02 python keywords and identifiers
 
Data types in python
Data types in pythonData types in python
Data types in python
 
Python dictionary
Python dictionaryPython dictionary
Python dictionary
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
11 Unit 1 Chapter 03 Data Handling
11   Unit 1 Chapter 03 Data Handling11   Unit 1 Chapter 03 Data Handling
11 Unit 1 Chapter 03 Data Handling
 
File Handling Python
File Handling PythonFile Handling Python
File Handling Python
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Python Programming - XI. String Manipulation and Regular Expressions
Python Programming - XI. String Manipulation and Regular ExpressionsPython Programming - XI. String Manipulation and Regular Expressions
Python Programming - XI. String Manipulation and Regular Expressions
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
 

Semelhante a Chapter 16 Dictionaries

"Python Dictionary: The Key to Efficient Data Storage, Manipulation, and Vers...
"Python Dictionary: The Key to Efficient Data Storage, Manipulation, and Vers..."Python Dictionary: The Key to Efficient Data Storage, Manipulation, and Vers...
"Python Dictionary: The Key to Efficient Data Storage, Manipulation, and Vers...
ZainabHaneen
 
python full notes data types string and tuple
python full notes data types string and tuplepython full notes data types string and tuple
python full notes data types string and tuple
SukhpreetSingh519414
 

Semelhante a Chapter 16 Dictionaries (20)

Chapter 14 Dictionary.pptx
Chapter 14 Dictionary.pptxChapter 14 Dictionary.pptx
Chapter 14 Dictionary.pptx
 
Python dictionaries
Python dictionariesPython dictionaries
Python dictionaries
 
.net F# mutable dictionay
.net F# mutable dictionay.net F# mutable dictionay
.net F# mutable dictionay
 
Python03 course in_mumbai
Python03 course in_mumbaiPython03 course in_mumbai
Python03 course in_mumbai
 
Collections in Python - Where Data Finds Its Perfect Home.pdf
Collections in Python - Where Data Finds Its Perfect Home.pdfCollections in Python - Where Data Finds Its Perfect Home.pdf
Collections in Python - Where Data Finds Its Perfect Home.pdf
 
MITx 6.00.1x Introduction to Computer Science and Programming Using Python - ...
MITx 6.00.1x Introduction to Computer Science and Programming Using Python - ...MITx 6.00.1x Introduction to Computer Science and Programming Using Python - ...
MITx 6.00.1x Introduction to Computer Science and Programming Using Python - ...
 
Dictionaries and Sets in Python
Dictionaries and Sets in PythonDictionaries and Sets in Python
Dictionaries and Sets in Python
 
"Python Dictionary: The Key to Efficient Data Storage, Manipulation, and Vers...
"Python Dictionary: The Key to Efficient Data Storage, Manipulation, and Vers..."Python Dictionary: The Key to Efficient Data Storage, Manipulation, and Vers...
"Python Dictionary: The Key to Efficient Data Storage, Manipulation, and Vers...
 
Dictionaries and Sets in Python
Dictionaries and Sets in PythonDictionaries and Sets in Python
Dictionaries and Sets in Python
 
Lecture1
Lecture1Lecture1
Lecture1
 
Devry CIS 355A Full Course Latest
Devry CIS 355A Full Course LatestDevry CIS 355A Full Course Latest
Devry CIS 355A Full Course Latest
 
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScriptLotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
 
python full notes data types string and tuple
python full notes data types string and tuplepython full notes data types string and tuple
python full notes data types string and tuple
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on Python
 
Week 10.pptx
Week 10.pptxWeek 10.pptx
Week 10.pptx
 
These questions will be a bit advanced level 2
These questions will be a bit advanced level 2These questions will be a bit advanced level 2
These questions will be a bit advanced level 2
 
PRESENTATION ON PYTHON.pptx
PRESENTATION ON PYTHON.pptxPRESENTATION ON PYTHON.pptx
PRESENTATION ON PYTHON.pptx
 
A Recommender System for Refining Ekeko/X Transformation
A Recommender System for Refining Ekeko/X TransformationA Recommender System for Refining Ekeko/X Transformation
A Recommender System for Refining Ekeko/X Transformation
 
Python dictionary
Python dictionaryPython dictionary
Python dictionary
 
2 UNIT CH3 Dictionaries v1.ppt
2 UNIT CH3 Dictionaries v1.ppt2 UNIT CH3 Dictionaries v1.ppt
2 UNIT CH3 Dictionaries v1.ppt
 

Mais de Praveen M Jigajinni

Mais de Praveen M Jigajinni (20)

Chapter 09 design and analysis of algorithms
Chapter 09  design and analysis of algorithmsChapter 09  design and analysis of algorithms
Chapter 09 design and analysis of algorithms
 
Chapter 08 data file handling
Chapter 08 data file handlingChapter 08 data file handling
Chapter 08 data file handling
 
Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
 
Chapter 06 constructors and destructors
Chapter 06 constructors and destructorsChapter 06 constructors and destructors
Chapter 06 constructors and destructors
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
 
Chapter 04 object oriented programming
Chapter 04 object oriented programmingChapter 04 object oriented programming
Chapter 04 object oriented programming
 
Chapter 02 functions -class xii
Chapter 02   functions -class xiiChapter 02   functions -class xii
Chapter 02 functions -class xii
 
Unit 3 MongDB
Unit 3 MongDBUnit 3 MongDB
Unit 3 MongDB
 
Chapter 13 exceptional handling
Chapter 13 exceptional handlingChapter 13 exceptional handling
Chapter 13 exceptional handling
 
Chapter 10 data handling
Chapter 10 data handlingChapter 10 data handling
Chapter 10 data handling
 
Chapter 9 python fundamentals
Chapter 9 python fundamentalsChapter 9 python fundamentals
Chapter 9 python fundamentals
 
Chapter 8 getting started with python
Chapter 8 getting started with pythonChapter 8 getting started with python
Chapter 8 getting started with python
 
Chapter 7 basics of computational thinking
Chapter 7 basics of computational thinkingChapter 7 basics of computational thinking
Chapter 7 basics of computational thinking
 
Chapter 6 algorithms and flow charts
Chapter 6  algorithms and flow chartsChapter 6  algorithms and flow charts
Chapter 6 algorithms and flow charts
 
Chapter 5 boolean algebra
Chapter 5 boolean algebraChapter 5 boolean algebra
Chapter 5 boolean algebra
 
Chapter 4 number system
Chapter 4 number systemChapter 4 number system
Chapter 4 number system
 
Chapter 3 cloud computing and intro parrallel computing
Chapter 3 cloud computing and intro parrallel computingChapter 3 cloud computing and intro parrallel computing
Chapter 3 cloud computing and intro parrallel computing
 
Chapter 2 operating systems
Chapter 2 operating systemsChapter 2 operating systems
Chapter 2 operating systems
 
Chapter 1 computer fundamentals
Chapter 1 computer  fundamentalsChapter 1 computer  fundamentals
Chapter 1 computer fundamentals
 
Chapter 0 syllabus 2019 20
Chapter 0  syllabus 2019 20Chapter 0  syllabus 2019 20
Chapter 0 syllabus 2019 20
 

Último

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
fonyou31
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Último (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 

Chapter 16 Dictionaries

  • 2. Unit 2: Computational Thinking and Programming XI Computer Science (083) Board : CBSE Courtesy CBSE
  • 3. Unit II Computational Thinking and Programming (60 Theory periods + 45 Practical Periods) DCSc & Engg, PGDCA,ADCA,MCA.MSc(IT),Mtech(IT),MPhil (Comp. Sci) Department of Computer Science, Sainik School Amaravathinagar Cell No: 9431453730 Praveen M Jigajinni Prepared by Courtesy CBSE
  • 5. After studying this lesson, students will be able to:  Understand the need of dictionaries; Solve problems by using dictionaries; Get clear idea about dictionaries functions; and  Understand the difference between list and dictionary. LEARNING OUTCOMES
  • 7. A dictionary is like a list, but more in general. In a list, index value is an integer, while in a dictionary index value can be any other data type and are called keys. The key will be used as a string as it is easy to recall. A dictionary is an extremely useful data storage construct for storing and retrieving all key value pairs, where each element is accessed (or indexed) by a unique key. However, dictionary keys are not in sequences and hence maintain no left-to right order. WHAT IS DICTIONARY?
  • 8. We can refer to a dictionary as a mapping between a set of indices (which are called keys) and a set of values. Each key maps a value. The association of a key and a value is called a key-value pair. Syntax: my_dict = {'key1': 'value1','key2': 'value2','key3': 'value3'…'keyn': 'valuen'} KEY VALYE PAIR
  • 9. Curley brackets are used to represent a dictionary. Each pair in the dictionary is represented by a key and value separated by a colon. Multiple pairs are separated by vcomas DICTIONARIES
  • 10. A dictionary is an unordered collection of key- value pairs. A dictionary has a length, specifically the numb er of keyvalue pairs. A dictionary provides fast look up by key. The keys must be immutable object types. DICTIONARIES
  • 11. >>> A={1:"one",2:"two",3:"three"} STATE DIAGRAM A = 1 one 2 two 3 three KEYS VALUES
  • 12. CREATING A DICTIONARY – dict()
  • 13. CREATING DICTIONARAY – dict() The function dict ( ) is used to create a new dictionary with no items. This function is called built-in function. We can also create dictionary using {}.
  • 15. CREATING AND TRAVERSING DICTIONARAY
  • 16. CREATING AND TRAVERSING DICTIONARAY OUT PUT
  • 17. CREATING AND TRAVERSING DICTIONARAY OUT PUT
  • 18. DICTIONARAY – BUILT IN METHODS
  • 19. DICTIONARAY – BUILT IN METHODS Dictionary Method Meaning dict.clear() Removes all the elements of the dictionary dict.copy() Returns (shallow)copy of dictionary. dict.get(key, default=None) for key key, returns value or default if key not in dictionary (note that default's default is None) dict.items() returns a list of dict's (key, value) tuple pairs
  • 20. Dictionary Method Meaning dict.keys() returns list of dictionary dict's keys dict.setdefault key, default=None similar to get(), but will set dict[key]=default if key is not already in dict dict.update(dict2) adds dictionary dict2's key-values pairs to dict dict.values() returns list of dictionary dict's values DICTIONARAY – BUILT IN METHODS
  • 21. Dictionary Method Meaning dict.pop() returns list of dictionary dict's keys dict.popitem() similar to get(), but will set dict[key]=default if key is not already in dict DICTIONARAY – BUILT IN METHODS
  • 23. dict.clear() METHOD - OUTPUT Birthday dictionary cleared
  • 25. dict.copy() METHOD - OUTPUT copy method creates b2 dictionary
  • 26. dict.get() METHOD OUTPUT is in next slide! get method
  • 27. dict.get() METHOD - OUTPUT Creating a b2 dictionary using get method
  • 28. dict.items() METHOD OUTPUT is in next slide! items method
  • 29. dict.items() METHOD - OUTPUT items method returns dictionary content
  • 30. dict.keys() METHOD OUTPUT is in next slide! keys method
  • 31. dict.keys() METHOD - OUTPUT keys method returns dictionary keys
  • 33. dict.values() METHOD values method returns dictionary values
  • 34. dict.pop() METHOD pop method removes specified key values from the dictionary
  • 35. dict.popitem() METHOD popitem method removes values/items from the dictionary
  • 37. CLASS WORK/HOME WORK 1. Write a Python script to sort (ascending and descending) a dictionary by value. 2. Write a Python script to add a key to a dictionary. Sample Dictionary : {0: 10, 1: 20} Expected Result : {0: 10, 1: 20, 2: 30} 3. Write a Python script to concatenate following dictionaries to create a new one. Sample Dictionary : dic1={1:10, 2:20} dic2={3:30, 4:40} dic3={5:50,6:60} Expected Result : {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}
  • 38. CLASS WORK/HOME WORK 4. Write a Python script to check if a given key already exists in a dictionary. 5. Write a Python program to iterate over dictionaries using for loops. 6. Write a Python script to generate and print a dictionary that contains a number (between 1 and n) in the form (x, x*x). Sample Dictionary ( n = 5) : Expected Output : {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
  • 39. CLASS WORK/HOME WORK 7. Write a Python script to print a dictionary where the keys are numbers between 1 and 15 (both included) and the values are square of keys. Sample Dictionary {1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100, 11: 121, 12: 144, 13: 169, 14: 196, 15: 225} 8. Write a Python script to merge two Python dictionaries.
  • 40. CLASS WORK/HOME WORK 9. Write a Python program to iterate over dictionaries using for loops. 10. Write a Python program to sum all the items in a dictionary.
  • 43. Class Test Time: 40 Min Max Marks: 20 1. What is dictionary? give example 02 2. Write a python script to traverse a dictionary 05 3. Explain 5 list built in methods of dictionary 10 4. What is key value pair? Explain 05