SlideShare a Scribd company logo
1 of 10
Unit 1(Lesson7)
Introduction to Dictionary
Dictionary is an unordered collection of key and value pairs.
Note : While other compound data types (like lists, tuples, and sets) have only
values as an element, a dictionary has a key : value pair
General usage of dictionaries is to store key-value pairs like :
• Employees and their wages
• Countries and their capitals
• Commodities and their prices
In a dictionary, the keys should be unique, but the values can change. For example,
the price of a commodity may change over time, but its name will not change.
Immutable data types like number, string, tuple etc. are used for the key and any
data type is used for the value.
• Dictionaries are optimized to retrieve values when the keys are known.
• Dictionaries are represented using key-value pairs separated by commas inside
curly braces {}. The key-value pairs are represented as key : value. For example,
daily temperatures in major cities are mapped into a dictionary as
{ "Hyderabad": 27, "Chennai": 32, "Mumbai": 40}.
• Creating a dictionary:
• A dictionary can be created in two ways.
oUsing the built-in dict() function.
o Assigning elements directly.
• 1. Using built-in dict() function.
An empty dictionary can be created as follows :
mydict = dict() # Creating an empty dictionary called mydict
print(type(mydict)) # Printing data type of mydict.
print(mydict) # Prints empty dictionary.
Output :
<class 'dict'>
{}
mydict = dict(Hyderabad = 20, Delhi = 30) # A dictionary with two key pairs is created.
print(mydict) # Prints the dictionary
Output :
{'Hyderabad': 20, 'Delhi': 30}
A dictionary with elements can be created as follows :
Note : The two key pairs are specified in the dict() function as comma separated key =
value.
• 2. Assigning elements directly.
A dictionary is created using direct assignment as follows :
mydict = {1:"one", 2 :"two", 3:"three"} # Create a dictionary with three key-value pairs.
print(mydict) # Printing the dictionary
print(type(mydict)) # will print output as follows
Output :
{1:"one", 2 :"two", 3:"three"}
<class 'dict'>
Which of the following options are correct?
Which of the following is feature of Dictionary?
1. Keys are unique within a dictionary.
2. Keys must be of an immutable data type.
3. Dictionary is mutable.
4. dictionary() function is used to create an empty dictionary.
a) All options are correct
b) 1,2 and 3 only
c) 3 and 4 only
d) 1,3 and 4 only
Which of the following options are correct?
Which of the following is feature of Dictionary?
1. Keys are unique within a dictionary.
2. Keys must be of an immutable data type.
3. Dictionary is mutable.
4. dictionary() function is used to create an empty dictionary.
a) All options are correct
b) 1,2 and 3 only
c) 3 and 4 only
d) 1,3 and 4 only

More Related Content

Similar to Unit 1(Lesson7).pptx

2 UNIT CH3 Dictionaries v1.ppt
2 UNIT CH3 Dictionaries v1.ppt2 UNIT CH3 Dictionaries v1.ppt
2 UNIT CH3 Dictionaries v1.ppttocidfh
 
Programming in python Unit-1 Part-1
Programming in python Unit-1 Part-1Programming in python Unit-1 Part-1
Programming in python Unit-1 Part-1Vikram Nandini
 
An Introduction to Tuple List Dictionary in Python
An Introduction to Tuple List Dictionary in PythonAn Introduction to Tuple List Dictionary in Python
An Introduction to Tuple List Dictionary in Pythonyashar Aliabasi
 
Python Dictionary
Python DictionaryPython Dictionary
Python DictionarySoba Arjun
 
Farhana shaikh webinar_dictionaries
Farhana shaikh webinar_dictionariesFarhana shaikh webinar_dictionaries
Farhana shaikh webinar_dictionariesFarhana Shaikh
 
Ch 7 Dictionaries 1.pptx
Ch 7 Dictionaries 1.pptxCh 7 Dictionaries 1.pptx
Ch 7 Dictionaries 1.pptxKanchanaRSVVV
 
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 tupleSukhpreetSingh519414
 
Python dictionary
Python dictionaryPython dictionary
Python dictionaryeman lotfy
 
Mapping Data Types In Python.pptx
Mapping Data Types In Python.pptxMapping Data Types In Python.pptx
Mapping Data Types In Python.pptxAnveshbandalla
 
Pa1 dictionaries subset
Pa1 dictionaries subsetPa1 dictionaries subset
Pa1 dictionaries subsetaiclub_slides
 
Module 3,4.pptx
Module 3,4.pptxModule 3,4.pptx
Module 3,4.pptxSandeepR95
 
Dictionary part 1
Dictionary part 1Dictionary part 1
Dictionary part 1RishuKaul2
 
unit 4,Indexes in database.docx
unit 4,Indexes in database.docxunit 4,Indexes in database.docx
unit 4,Indexes in database.docxRaviRajput416403
 

Similar to Unit 1(Lesson7).pptx (20)

2 UNIT CH3 Dictionaries v1.ppt
2 UNIT CH3 Dictionaries v1.ppt2 UNIT CH3 Dictionaries v1.ppt
2 UNIT CH3 Dictionaries v1.ppt
 
Programming in python Unit-1 Part-1
Programming in python Unit-1 Part-1Programming in python Unit-1 Part-1
Programming in python Unit-1 Part-1
 
An Introduction to Tuple List Dictionary in Python
An Introduction to Tuple List Dictionary in PythonAn Introduction to Tuple List Dictionary in Python
An Introduction to Tuple List Dictionary in Python
 
Python Dictionary
Python DictionaryPython Dictionary
Python Dictionary
 
Farhana shaikh webinar_dictionaries
Farhana shaikh webinar_dictionariesFarhana shaikh webinar_dictionaries
Farhana shaikh webinar_dictionaries
 
Pytho dictionaries
Pytho dictionaries Pytho dictionaries
Pytho dictionaries
 
Dictionary.pptx
Dictionary.pptxDictionary.pptx
Dictionary.pptx
 
Ch 7 Dictionaries 1.pptx
Ch 7 Dictionaries 1.pptxCh 7 Dictionaries 1.pptx
Ch 7 Dictionaries 1.pptx
 
ppt_pspp.pdf
ppt_pspp.pdfppt_pspp.pdf
ppt_pspp.pdf
 
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
 
Python dictionary
Python dictionaryPython dictionary
Python dictionary
 
Mapping Data Types In Python.pptx
Mapping Data Types In Python.pptxMapping Data Types In Python.pptx
Mapping Data Types In Python.pptx
 
Pa1 dictionaries subset
Pa1 dictionaries subsetPa1 dictionaries subset
Pa1 dictionaries subset
 
Module 3,4.pptx
Module 3,4.pptxModule 3,4.pptx
Module 3,4.pptx
 
Dictionary part 1
Dictionary part 1Dictionary part 1
Dictionary part 1
 
Dictionaries
DictionariesDictionaries
Dictionaries
 
Dictionaries in python
Dictionaries in pythonDictionaries in python
Dictionaries in python
 
unit 4,Indexes in database.docx
unit 4,Indexes in database.docxunit 4,Indexes in database.docx
unit 4,Indexes in database.docx
 
Python dictionaries
Python dictionariesPython dictionaries
Python dictionaries
 
Ankit
AnkitAnkit
Ankit
 

Recently uploaded

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
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.pptxPooja Bhuva
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
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Ữ Â...Nguyen Thanh Tu Collection
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
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.pptxheathfieldcps1
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 

Recently uploaded (20)

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
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Ữ Â...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
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
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 

Unit 1(Lesson7).pptx

  • 2. Dictionary is an unordered collection of key and value pairs. Note : While other compound data types (like lists, tuples, and sets) have only values as an element, a dictionary has a key : value pair
  • 3. General usage of dictionaries is to store key-value pairs like : • Employees and their wages • Countries and their capitals • Commodities and their prices In a dictionary, the keys should be unique, but the values can change. For example, the price of a commodity may change over time, but its name will not change. Immutable data types like number, string, tuple etc. are used for the key and any data type is used for the value.
  • 4. • Dictionaries are optimized to retrieve values when the keys are known. • Dictionaries are represented using key-value pairs separated by commas inside curly braces {}. The key-value pairs are represented as key : value. For example, daily temperatures in major cities are mapped into a dictionary as { "Hyderabad": 27, "Chennai": 32, "Mumbai": 40}.
  • 5. • Creating a dictionary: • A dictionary can be created in two ways. oUsing the built-in dict() function. o Assigning elements directly.
  • 6. • 1. Using built-in dict() function. An empty dictionary can be created as follows : mydict = dict() # Creating an empty dictionary called mydict print(type(mydict)) # Printing data type of mydict. print(mydict) # Prints empty dictionary. Output : <class 'dict'> {}
  • 7. mydict = dict(Hyderabad = 20, Delhi = 30) # A dictionary with two key pairs is created. print(mydict) # Prints the dictionary Output : {'Hyderabad': 20, 'Delhi': 30} A dictionary with elements can be created as follows : Note : The two key pairs are specified in the dict() function as comma separated key = value.
  • 8. • 2. Assigning elements directly. A dictionary is created using direct assignment as follows : mydict = {1:"one", 2 :"two", 3:"three"} # Create a dictionary with three key-value pairs. print(mydict) # Printing the dictionary print(type(mydict)) # will print output as follows Output : {1:"one", 2 :"two", 3:"three"} <class 'dict'>
  • 9. Which of the following options are correct? Which of the following is feature of Dictionary? 1. Keys are unique within a dictionary. 2. Keys must be of an immutable data type. 3. Dictionary is mutable. 4. dictionary() function is used to create an empty dictionary. a) All options are correct b) 1,2 and 3 only c) 3 and 4 only d) 1,3 and 4 only
  • 10. Which of the following options are correct? Which of the following is feature of Dictionary? 1. Keys are unique within a dictionary. 2. Keys must be of an immutable data type. 3. Dictionary is mutable. 4. dictionary() function is used to create an empty dictionary. a) All options are correct b) 1,2 and 3 only c) 3 and 4 only d) 1,3 and 4 only