SlideShare a Scribd company logo
1 of 26
Download to read offline
Operation: Sets and Dictionary
Lesson 2.3
CHAPTER
2
What are the string functions?
How do you get input
from the user?
Set Operations
In This Lesson
Operations in Dictionary
Set Operations
Set Operations
• Union
• Intersection
• Difference
• Symmetric difference
Union
• Union sets is a set of all elements from both sets.
• It is performed using the “|” operator and the
union() method.
Example
x = {1,2,3,4,5}
y = {3,4,5,6,7}
print(x|y)
print(x.union(y))
{1, 2, 3, 4, 5, 6, 7}
{1, 2, 3, 4, 5, 6, 7}
Answer This
What is a union set?
Intersection
• Intersection is sets is a set of elements that are
common to both sets.
• It uses the “&” operator and the intersection() method.
Example
x = {1,2,3,4,5}
y = {3,4,5,6,7}
print(x&y)
print(x.intersection(y))
{3, 4, 5}
{3, 4, 5}
Difference
• Difference in sets is a set where the difference of set x
to y (x - y) is a set of elements that are only in x but not
in y.
• It is performed using the “-” operator and the
difference() method.
Example
x = {1,2,3,4,5}
y = {3,4,5,6,7}
print(x-y)
print(x.difference(y))
print(y-x)
print(y.difference(x))
{1, 2}
{1, 2}
{6, 7}
{6, 7}
Symmetric Difference
• Symmetric difference in sets is a set where the
symmetric difference of x and y is a set of elements
that is not found in both sets.
• It is performed using the “^” operator and the
symmetric_difference() method.
Example
x = {1,2,3,4,5}
y = {3,4,5,6,7}
print(x^y)
print(x.symmetric_difference(y))
print(y^x)
print(y.symmetric_difference(x))
{1, 2, 6, 7}
{1, 2, 6, 7}
{1, 2, 6, 7}
{1, 2, 6, 7}
Answer This
How do you describe the symmetric
difference in sets?
Find the Union, Intersection, Difference and Symmetric
Difference of the following sets:
A = {2,4,12,42,9,17}
B = {3,12,17,5,34,7,10}
C = {34,25,7,42,4,6,11,55}
Exercise
Operations in Dictionary
Dictionary Methods
• Get()
• Clear()
• Copy()
• Items()
• Update()
• Pop()
• Zip()
Example
students = {"Name":"David","Age":16}
print(students.get("Name"))
students["Age"]=30
print(students.get("Age"))
print(students.pop("Name"))
David
30
David
Answer This
How do you differentiate set operations
from dictionary operations?
Other Dictionary Methods
• fromkeys(seq[, v])
• items()
• keys()
• popitem()
• setdefault(key[,d])
• values()
Answer This
What are the methods in accessing
the elements of the dictionary?
Create a program to convert the following lists to a
dictionary. Hint: use zip().
employee = ["Cynthia","Austin","Cesar"]
salary = [40000,30000,45000]
Output:
{'Cynthia': 40000, 'Austin': 30000, 'Cesar': 45000}
Exercise
Answer This
What are the characteristics of each
type of set operation?
Do the activity on
page 84.
Lesson Exercises

More Related Content

Similar to Pyhton dictionary.pdf

Storyboard math
Storyboard mathStoryboard math
Storyboard math
shandex
 
PPt on Functions
PPt on FunctionsPPt on Functions
PPt on Functions
coolhanddav
 
L1 functions, domain & range
L1 functions, domain & rangeL1 functions, domain & range
L1 functions, domain & range
James Tagara
 
Chapter 2 Mathematical Language and Symbols.pdf
Chapter 2 Mathematical Language and Symbols.pdfChapter 2 Mathematical Language and Symbols.pdf
Chapter 2 Mathematical Language and Symbols.pdf
RaRaRamirez
 
Calculus - Functions Review
Calculus - Functions ReviewCalculus - Functions Review
Calculus - Functions Review
hassaanciit
 

Similar to Pyhton dictionary.pdf (20)

Systems of equations
Systems of equationsSystems of equations
Systems of equations
 
Calculus - 1 Functions, domain and range
Calculus - 1 Functions, domain and rangeCalculus - 1 Functions, domain and range
Calculus - 1 Functions, domain and range
 
Fst ch3 notes
Fst ch3 notesFst ch3 notes
Fst ch3 notes
 
WEEK-1.pdf
WEEK-1.pdfWEEK-1.pdf
WEEK-1.pdf
 
Storyboard math
Storyboard mathStoryboard math
Storyboard math
 
PPt on Functions
PPt on FunctionsPPt on Functions
PPt on Functions
 
Functions
FunctionsFunctions
Functions
 
Function Analysis v.2
Function Analysis v.2Function Analysis v.2
Function Analysis v.2
 
Functions
FunctionsFunctions
Functions
 
(7) Lesson 5.6 - Simplify Algebraic Expressions
(7) Lesson 5.6 - Simplify Algebraic Expressions(7) Lesson 5.6 - Simplify Algebraic Expressions
(7) Lesson 5.6 - Simplify Algebraic Expressions
 
L1 functions, domain & range
L1 functions, domain & rangeL1 functions, domain & range
L1 functions, domain & range
 
Top schools in gudgao
Top schools in gudgaoTop schools in gudgao
Top schools in gudgao
 
3 handouts section3-11
3 handouts section3-113 handouts section3-11
3 handouts section3-11
 
8517ijaia06
8517ijaia068517ijaia06
8517ijaia06
 
Numarical values
Numarical valuesNumarical values
Numarical values
 
Numarical values highlighted
Numarical values highlightedNumarical values highlighted
Numarical values highlighted
 
Chapter 2 Mathematical Language and Symbols.pdf
Chapter 2 Mathematical Language and Symbols.pdfChapter 2 Mathematical Language and Symbols.pdf
Chapter 2 Mathematical Language and Symbols.pdf
 
3.1 Functions and Function Notation
3.1 Functions and Function Notation3.1 Functions and Function Notation
3.1 Functions and Function Notation
 
F5233444
F5233444F5233444
F5233444
 
Calculus - Functions Review
Calculus - Functions ReviewCalculus - Functions Review
Calculus - Functions Review
 

More from ElijahSantos4

More from ElijahSantos4 (13)

LESSON POWERPOINT, LEARN HOW TO DO POWERPOINT LESSON 2
LESSON POWERPOINT, LEARN HOW TO DO POWERPOINT LESSON 2LESSON POWERPOINT, LEARN HOW TO DO POWERPOINT LESSON 2
LESSON POWERPOINT, LEARN HOW TO DO POWERPOINT LESSON 2
 
LP4E-U06L01 Presentation - POWERPOINT PRESENTATION
LP4E-U06L01 Presentation -  POWERPOINT PRESENTATIONLP4E-U06L01 Presentation -  POWERPOINT PRESENTATION
LP4E-U06L01 Presentation - POWERPOINT PRESENTATION
 
LESSON FOR POWERPOINT - LESSON NUMBER 1 - HOW TO DO POWERPOINT
LESSON FOR POWERPOINT - LESSON NUMBER 1 - HOW TO DO POWERPOINTLESSON FOR POWERPOINT - LESSON NUMBER 1 - HOW TO DO POWERPOINT
LESSON FOR POWERPOINT - LESSON NUMBER 1 - HOW TO DO POWERPOINT
 
Introduction to Webpage creation and HTML
Introduction to Webpage creation and HTMLIntroduction to Webpage creation and HTML
Introduction to Webpage creation and HTML
 
JAVASCRIPT LESSON 20 - LEARNJAVASCRIPT - ARRAYS
JAVASCRIPT LESSON 20 - LEARNJAVASCRIPT - ARRAYSJAVASCRIPT LESSON 20 - LEARNJAVASCRIPT - ARRAYS
JAVASCRIPT LESSON 20 - LEARNJAVASCRIPT - ARRAYS
 
CHARACTERISTICS OF COMPUTER LEARNING FOR ELEMNTARY
CHARACTERISTICS OF COMPUTER LEARNING FOR ELEMNTARYCHARACTERISTICS OF COMPUTER LEARNING FOR ELEMNTARY
CHARACTERISTICS OF COMPUTER LEARNING FOR ELEMNTARY
 
SONGWRITING LESSON - HOW TO WRITE A SONG
SONGWRITING LESSON - HOW TO WRITE A SONGSONGWRITING LESSON - HOW TO WRITE A SONG
SONGWRITING LESSON - HOW TO WRITE A SONG
 
FORMS OF MUSIC- LNA - LOCAL MUSIC TYPES AND FORMS
FORMS OF MUSIC- LNA - LOCAL MUSIC TYPES AND FORMSFORMS OF MUSIC- LNA - LOCAL MUSIC TYPES AND FORMS
FORMS OF MUSIC- LNA - LOCAL MUSIC TYPES AND FORMS
 
Drug Abuse Education - PPT about drugs and solution
Drug Abuse Education - PPT about drugs and solutionDrug Abuse Education - PPT about drugs and solution
Drug Abuse Education - PPT about drugs and solution
 
DC-CH01Intro.pptx
DC-CH01Intro.pptxDC-CH01Intro.pptx
DC-CH01Intro.pptx
 
FACT OR BLUFF.pptx
FACT OR BLUFF.pptxFACT OR BLUFF.pptx
FACT OR BLUFF.pptx
 
Python-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptxPython-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptx
 
May-30-2021-a.m.-worship.pptx
May-30-2021-a.m.-worship.pptxMay-30-2021-a.m.-worship.pptx
May-30-2021-a.m.-worship.pptx
 

Recently uploaded

DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Recently uploaded (20)

Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stage
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptx
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 

Pyhton dictionary.pdf