SlideShare a Scribd company logo
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

PDF
"Python Dictionary: The Key to Efficient Data Storage, Manipulation, and Vers...
ZainabHaneen
 
PPTX
PYTHON Data structures Fundamentals: DICTIONARIES
KanadamKarteekaPavan1
 
PPTX
Python Fundamental Data structures: Dictionaries
KanadamKarteekaPavan1
 
PDF
CHAPTER- 9 PYTHON DICTIONARIES.pdf computer science
Bavish5
 
PPTX
Meaning of Dictionary in python language
PRASHANTMISHRA16761
 
PPTX
Chapter 14 Dictionary.pptx
jchandrasekhar3
 
PPTX
Dictionariesasdfghjsdfghjklsdfghjkl.pptx
cjrfailure
 
PPTX
Dictionaries and Sets
Munazza-Mah-Jabeen
 
"Python Dictionary: The Key to Efficient Data Storage, Manipulation, and Vers...
ZainabHaneen
 
PYTHON Data structures Fundamentals: DICTIONARIES
KanadamKarteekaPavan1
 
Python Fundamental Data structures: Dictionaries
KanadamKarteekaPavan1
 
CHAPTER- 9 PYTHON DICTIONARIES.pdf computer science
Bavish5
 
Meaning of Dictionary in python language
PRASHANTMISHRA16761
 
Chapter 14 Dictionary.pptx
jchandrasekhar3
 
Dictionariesasdfghjsdfghjklsdfghjkl.pptx
cjrfailure
 
Dictionaries and Sets
Munazza-Mah-Jabeen
 

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

PPTX
Python Dynamic Data type List & Dictionaries
RuchiNagar3
 
PPTX
Chapter 16 Dictionaries
Praveen M Jigajinni
 
PPTX
DICTIONARIES TUTORIALS FOR ADVANCED LEARNING OF YTHON PROGRAMMING
examcelldavrng
 
PPTX
Dictionary
Pooja B S
 
PPTX
Dictionary in python Dictionary in python Dictionary in pDictionary in python...
sumanthcmcse
 
PPTX
Python dictionary
Mohammed Sikander
 
PPTX
Dictionaries.pptx
akshat205573
 
PPTX
DICTIONARIES (1).pptx
KalashJain27
 
PPTX
advanced database management system by uni
VaibhavSrivastav52
 
PPT
2 UNIT CH3 Dictionaries v1.ppt
tocidfh
 
PDF
Programming in python Unit-1 Part-1
Vikram Nandini
 
PPTX
An Introduction to Tuple List Dictionary in Python
yashar Aliabasi
 
PPTX
SQL_all_commnads_aggregate_functions.pptx
fakee00789
 
PDF
Python Dictionary
Soba Arjun
 
PPTX
Farhana shaikh webinar_dictionaries
Farhana Shaikh
 
PPTX
RELATIONALfsaaaaaaaaaaaakyagsgs MODEL.pptx
satish7588
 
PPTX
Dictionary.pptx
RishuVerma34
 
PPTX
Ch 7 Dictionaries 1.pptx
KanchanaRSVVV
 
PDF
ppt_pspp.pdf
ShereenAhmedMohamed
 
Python Dynamic Data type List & Dictionaries
RuchiNagar3
 
Chapter 16 Dictionaries
Praveen M Jigajinni
 
DICTIONARIES TUTORIALS FOR ADVANCED LEARNING OF YTHON PROGRAMMING
examcelldavrng
 
Dictionary
Pooja B S
 
Dictionary in python Dictionary in python Dictionary in pDictionary in python...
sumanthcmcse
 
Python dictionary
Mohammed Sikander
 
Dictionaries.pptx
akshat205573
 
DICTIONARIES (1).pptx
KalashJain27
 
advanced database management system by uni
VaibhavSrivastav52
 
2 UNIT CH3 Dictionaries v1.ppt
tocidfh
 
Programming in python Unit-1 Part-1
Vikram Nandini
 
An Introduction to Tuple List Dictionary in Python
yashar Aliabasi
 
SQL_all_commnads_aggregate_functions.pptx
fakee00789
 
Python Dictionary
Soba Arjun
 
Farhana shaikh webinar_dictionaries
Farhana Shaikh
 
RELATIONALfsaaaaaaaaaaaakyagsgs MODEL.pptx
satish7588
 
Dictionary.pptx
RishuVerma34
 
Ch 7 Dictionaries 1.pptx
KanchanaRSVVV
 
ppt_pspp.pdf
ShereenAhmedMohamed
 

Recently uploaded (20)

PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PPTX
CDH. pptx
AneetaSharma15
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
PDF
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
PDF
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
PPTX
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
PPTX
How to Apply for a Job From Odoo 18 Website
Celine George
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PPTX
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
PPTX
BASICS IN COMPUTER APPLICATIONS - UNIT I
suganthim28
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
Basics and rules of probability with real-life uses
ravatkaran694
 
CDH. pptx
AneetaSharma15
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
How to Apply for a Job From Odoo 18 Website
Celine George
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
BASICS IN COMPUTER APPLICATIONS - UNIT I
suganthim28
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 

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