SlideShare a Scribd company logo
1 of 19
Arrays in Python
Part ||
‫إعداد‬:
‫م‬.‫محمد‬ ‫علي‬
objectives
 Sets
 dictionaries
Sets
 A set is a collection which is unordered and unindexed. In Python sets are
written with curly brackets ({ })
 Example:
 set1 = {"apple", "banana", "cherry"}
print(set1)
 Note: Sets are unordered, so you cannot be sure in which order the items will
appear.
 set1 = {"apple", "banana", "cherry"}
for x in set1:
print(x)
 Result:
banana
cherry
apple
Check if item in sets
 print("banana" in set1)
 Result: (True)
 Change Item: Once a set is created, you cannot change its items, but you
can add new items, by using add() method
 set1 = {"apple", "banana", "cherry"}
set1.add("orange")
print(set1)
 Result:
 {'banana', 'cherry', 'apple', 'orange'}
Change values in sets
 Add multiple items to a set, using the update method
 Example:
 set1 = {"apple", "banana", "cherry"}
set1.update(["orange", "mango", "grapes"])
print(set1)
 Result:
{'grapes', 'orange', 'mongo', 'apple', 'cherry', 'banana'}
Deleted value from set
 We can use remove(), discard() and pop()
 remove(“item”): if the item not found will show an error
 discard(“item”): if the item not found will not show an error
 pop(): will remove the last item from set
 Note: Sets are unordered, so when using the pop() method, you will not
know which item that gets removed.
 The clear() method empties the set
 The del keyword will delete the set completely
 So, clear() will delete the items from the set but del will delete set from the
memory
Join two sets
 There are several ways to join two or more sets in Python.
 We can use union() method returns a new set with all items from both sets
example:
set1 = {"a", "b" , "c"}
set2 = {1, 2, 3}
set3 = set1.union(set2)
print(set3)
 We can use update() method inserts the items in set2 into set1 example:
set1 = {"a", "b" , "c"}
set2 = {1, 2, 3}
set1.update(set2)
print(set1)
 Note: both union() and update() will exclude any duplicate items.
Set methods
Method Description
add() Adds an element to the set
clear() Removes all the elements from the set
copy() Returns a copy of the set
difference()
Returns a set containing the difference
between two or more sets
difference_update()
Removes the items in this set that are
also included in another, specified set
discard() Remove the specified item
intersection()
Returns a set, that is the intersection of
two other sets
intersection_update()
Removes the items in this set that are not
present in other, specified set(s)
isdisjoint()
Returns whether two sets have a
intersection or not
Set methods cont
 issubset()
Returns whether another set contains this set or not
 issuperset()
Returns whether this set contains another set or not
 pop()
Removes an element from the set
 remove()
Removes the specified element
 symmetric_difference()
Returns a set with the symmetric differences of two sets
 symmetric_difference_update()
inserts the symmetric differences from this set and another
 union()
Return a set containing the union of sets
 update()
Update the set with the union of this set and others
Dictionaries
 A dictionary is a collection which is unordered, changeable and indexed. In
Python dictionaries are written with curly brackets, and they have keys and
values.
 Example:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict)
Result:
{'brand': 'Ford', 'model': 'Mustang', 'year': 1964}
Get an item
 You can access the items of a dictionary by referring to its key name, inside
square brackets
 Example:
x = thisdict["model"]
Print(x)
Result:
Mustang
 There is also a method called get() will give the same result
x = thisdict.get(“model”)
Print(x)
Result:
Mustang
Change values
 You can change the value of a specific item by referring to its key name
 Example:
 thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict["year"] = 2020
 This example will change the year to 2020
Loops over dictionaries
 The following will give all key names in dictionary:
for x in thisdict:
print(x)
 The following will give all values names in dictionary:
for x in thisdict:
print(thisdict[x])
 We can also use values() function to return values of a dictionary
for x in thisdict.values():
print(x)
 To get both of key and values we use items() method:
for x, y in thisdict.items():
print(x, y)
 X for the key and y for the value
Check for items in dictionaries
 if "model" in thisdict:
print("Yes, 'model' is one of the keys in the thisdict dictionary")
 To add item to dictionary we use the following:
thisdict["color"] = "red"
print(thisdict)
 Result:
{'brand': 'Ford', 'model': 'Mustang', 'year': 2020, 'color': 'red'}
Removing items
 We can use pop(),popitem(),clear() method and del keyword
 pop(“item”): remove specific key name
 popitem(): will remove the last key, in python 3.7 will remove a random
item
 The del keyword can delete the dictionary completely
del thisdict
 The clear() method empties the dictionary
Copy the dictionaries
 If we write dict2=dict1, in this way dict2 will be a reference for dict1 and
any change on dict1 will happened the same change on dict2
 There are ways to make a copy, one way is to use the built-in Dictionary
method copy()
mydict = thisdict.copy()
 Another way to make a copy is to use the built-in method
mydict = dict(thisdict)
Nested Dictionaries
 A dictionary can also contain many dictionaries, this is called nested
dictionaries
 Example
myfamily = {
"child1" : {
"name" : “Ali",
"year" : 1995
},
"child2" : {
"name" : “Ghadeer",
"year" : 1994
},
"child3" : {
"name" : “Mohammad",
"year" : 1996
}
}
Nested Dictionaries
 Create three dictionaries, than create one dictionary that will contain the other three
dictionaries
 child1 = {
"name" : “Ali",
"year" : 1995
}
child2 = {
"name" : “Ghadeer",
"year" : 1994
}
child3 = {
"name" : “Mohammad",
"year" : 1996
}
myfamily = {
"child1" : child1,
"child2" : child2,
"child3" : child3
}
Dictionary Methods
Method Description
clear() Removes all the elements from the dictionary
copy() Returns a copy of the dictionary
fromkeys()
Returns a dictionary with the specified keys and
value
get() Returns the value of the specified key
items()
Returns a list containing a tuple for each key value
pair
keys() Returns a list containing the dictionary's keys
pop() Removes the element with the specified key
popitem() Removes the last inserted key-value pair
setdefault()
Returns the value of the specified key. If the key does
not exist: insert the key, with the specified value
update()
Updates the dictionary with the specified key-value
pairs
values() Returns a list of all the values in the dictionary

More Related Content

What's hot

Power shell object
Power shell objectPower shell object
Power shell objectLearningTech
 
Python data structures
Python data structuresPython data structures
Python data structureskalyanibedekar
 
Google Sheets in Python with gspread
Google Sheets in Python with gspreadGoogle Sheets in Python with gspread
Google Sheets in Python with gspreadJure Cuhalev
 
The Chain Rule, Part 1
The Chain Rule, Part 1The Chain Rule, Part 1
The Chain Rule, Part 1Pablo Antuna
 
Introduction to Arrays in Programming
Introduction to Arrays in ProgrammingIntroduction to Arrays in Programming
Introduction to Arrays in ProgrammingJulian Bunn
 
Big Data Mining in Indian Economic Survey 2017
Big Data Mining in Indian Economic Survey 2017Big Data Mining in Indian Economic Survey 2017
Big Data Mining in Indian Economic Survey 2017Parth Khare
 
Python for Data Science and Scientific Computing
Python for Data Science and Scientific ComputingPython for Data Science and Scientific Computing
Python for Data Science and Scientific ComputingAbhijit Kar Gupta
 
Phylogenetics in R
Phylogenetics in RPhylogenetics in R
Phylogenetics in Rschamber
 
Pycon 2011 talk (may not be final, note)
Pycon 2011 talk (may not be final, note)Pycon 2011 talk (may not be final, note)
Pycon 2011 talk (may not be final, note)c.titus.brown
 
Binomial Theorem 6/Coeff of a power of x
Binomial Theorem 6/Coeff of a power of xBinomial Theorem 6/Coeff of a power of x
Binomial Theorem 6/Coeff of a power of xLakshmikanta Satapathy
 

What's hot (16)

Power shell object
Power shell objectPower shell object
Power shell object
 
Python data structures
Python data structuresPython data structures
Python data structures
 
Google Sheets in Python with gspread
Google Sheets in Python with gspreadGoogle Sheets in Python with gspread
Google Sheets in Python with gspread
 
The Chain Rule, Part 1
The Chain Rule, Part 1The Chain Rule, Part 1
The Chain Rule, Part 1
 
Array
ArrayArray
Array
 
Introduction to Arrays in Programming
Introduction to Arrays in ProgrammingIntroduction to Arrays in Programming
Introduction to Arrays in Programming
 
Big Data Mining in Indian Economic Survey 2017
Big Data Mining in Indian Economic Survey 2017Big Data Mining in Indian Economic Survey 2017
Big Data Mining in Indian Economic Survey 2017
 
Python for Data Science and Scientific Computing
Python for Data Science and Scientific ComputingPython for Data Science and Scientific Computing
Python for Data Science and Scientific Computing
 
proj1v2
proj1v2proj1v2
proj1v2
 
Python Basic
Python BasicPython Basic
Python Basic
 
Phylogenetics in R
Phylogenetics in RPhylogenetics in R
Phylogenetics in R
 
Summary_Onset (1)
Summary_Onset (1)Summary_Onset (1)
Summary_Onset (1)
 
Chapter 1 python basics
Chapter 1   python basicsChapter 1   python basics
Chapter 1 python basics
 
Begin with Python
Begin with PythonBegin with Python
Begin with Python
 
Pycon 2011 talk (may not be final, note)
Pycon 2011 talk (may not be final, note)Pycon 2011 talk (may not be final, note)
Pycon 2011 talk (may not be final, note)
 
Binomial Theorem 6/Coeff of a power of x
Binomial Theorem 6/Coeff of a power of xBinomial Theorem 6/Coeff of a power of x
Binomial Theorem 6/Coeff of a power of x
 

Similar to Seventh session

Week 10.pptx
Week 10.pptxWeek 10.pptx
Week 10.pptxCruiseCH
 
Data Type In Python.pptx
Data Type In Python.pptxData Type In Python.pptx
Data Type In Python.pptxhothyfa
 
Stata Cheat Sheets (all)
Stata Cheat Sheets (all)Stata Cheat Sheets (all)
Stata Cheat Sheets (all)Laura Hughes
 
The Ring programming language version 1.5.2 book - Part 21 of 181
The Ring programming language version 1.5.2 book - Part 21 of 181The Ring programming language version 1.5.2 book - Part 21 of 181
The Ring programming language version 1.5.2 book - Part 21 of 181Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189Mahmoud Samir Fayed
 
Cheat Sheet for Stata v15.00 PDF Complete
Cheat Sheet for Stata v15.00 PDF CompleteCheat Sheet for Stata v15.00 PDF Complete
Cheat Sheet for Stata v15.00 PDF CompleteTsamaraLuthfia1
 
Stata cheat sheet: data transformation
Stata  cheat sheet: data transformationStata  cheat sheet: data transformation
Stata cheat sheet: data transformationTim Essam
 
The Ring programming language version 1.10 book - Part 30 of 212
The Ring programming language version 1.10 book - Part 30 of 212The Ring programming language version 1.10 book - Part 30 of 212
The Ring programming language version 1.10 book - Part 30 of 212Mahmoud Samir Fayed
 
Question In C Programming In mathematics, a set is a colle...Sav.pdf
Question In C Programming In mathematics, a set is a colle...Sav.pdfQuestion In C Programming In mathematics, a set is a colle...Sav.pdf
Question In C Programming In mathematics, a set is a colle...Sav.pdfarihantcomp1008
 
The Ring programming language version 1.5.4 book - Part 22 of 185
The Ring programming language version 1.5.4 book - Part 22 of 185The Ring programming language version 1.5.4 book - Part 22 of 185
The Ring programming language version 1.5.4 book - Part 22 of 185Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 94 of 202
The Ring programming language version 1.8 book - Part 94 of 202The Ring programming language version 1.8 book - Part 94 of 202
The Ring programming language version 1.8 book - Part 94 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88Mahmoud Samir Fayed
 
Stata cheatsheet transformation
Stata cheatsheet transformationStata cheatsheet transformation
Stata cheatsheet transformationLaura Hughes
 
Let’s Talk About Ruby
Let’s Talk About RubyLet’s Talk About Ruby
Let’s Talk About RubyIan Bishop
 
Stata cheat sheet: data processing
Stata cheat sheet: data processingStata cheat sheet: data processing
Stata cheat sheet: data processingTim Essam
 

Similar to Seventh session (20)

Week 10.pptx
Week 10.pptxWeek 10.pptx
Week 10.pptx
 
Sets
SetsSets
Sets
 
Data Type In Python.pptx
Data Type In Python.pptxData Type In Python.pptx
Data Type In Python.pptx
 
Stata Cheat Sheets (all)
Stata Cheat Sheets (all)Stata Cheat Sheets (all)
Stata Cheat Sheets (all)
 
The Ring programming language version 1.5.2 book - Part 21 of 181
The Ring programming language version 1.5.2 book - Part 21 of 181The Ring programming language version 1.5.2 book - Part 21 of 181
The Ring programming language version 1.5.2 book - Part 21 of 181
 
The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189
 
Dictionary
DictionaryDictionary
Dictionary
 
Cheat Sheet for Stata v15.00 PDF Complete
Cheat Sheet for Stata v15.00 PDF CompleteCheat Sheet for Stata v15.00 PDF Complete
Cheat Sheet for Stata v15.00 PDF Complete
 
Stata cheat sheet: data transformation
Stata  cheat sheet: data transformationStata  cheat sheet: data transformation
Stata cheat sheet: data transformation
 
The Ring programming language version 1.10 book - Part 30 of 212
The Ring programming language version 1.10 book - Part 30 of 212The Ring programming language version 1.10 book - Part 30 of 212
The Ring programming language version 1.10 book - Part 30 of 212
 
Question In C Programming In mathematics, a set is a colle...Sav.pdf
Question In C Programming In mathematics, a set is a colle...Sav.pdfQuestion In C Programming In mathematics, a set is a colle...Sav.pdf
Question In C Programming In mathematics, a set is a colle...Sav.pdf
 
The Ring programming language version 1.5.4 book - Part 22 of 185
The Ring programming language version 1.5.4 book - Part 22 of 185The Ring programming language version 1.5.4 book - Part 22 of 185
The Ring programming language version 1.5.4 book - Part 22 of 185
 
The Ring programming language version 1.8 book - Part 94 of 202
The Ring programming language version 1.8 book - Part 94 of 202The Ring programming language version 1.8 book - Part 94 of 202
The Ring programming language version 1.8 book - Part 94 of 202
 
Spsl vi unit final
Spsl vi unit finalSpsl vi unit final
Spsl vi unit final
 
Spsl v unit - final
Spsl v unit - finalSpsl v unit - final
Spsl v unit - final
 
The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88
 
Stata cheatsheet transformation
Stata cheatsheet transformationStata cheatsheet transformation
Stata cheatsheet transformation
 
Let’s Talk About Ruby
Let’s Talk About RubyLet’s Talk About Ruby
Let’s Talk About Ruby
 
Stata cheat sheet: data processing
Stata cheat sheet: data processingStata cheat sheet: data processing
Stata cheat sheet: data processing
 
Fst ch3 notes
Fst ch3 notesFst ch3 notes
Fst ch3 notes
 

More from AliMohammad155

#1 الدرس الأول من دروس مسار تعلم ال SQL Server بعنوان مخطط ال ERD والتكامل ا...
#1  الدرس الأول من دروس مسار تعلم ال SQL Server بعنوان مخطط ال ERD والتكامل ا...#1  الدرس الأول من دروس مسار تعلم ال SQL Server بعنوان مخطط ال ERD والتكامل ا...
#1 الدرس الأول من دروس مسار تعلم ال SQL Server بعنوان مخطط ال ERD والتكامل ا...AliMohammad155
 
شرح مبسط وبسيط لمفهوم ال VLAN
شرح مبسط وبسيط لمفهوم ال VLANشرح مبسط وبسيط لمفهوم ال VLAN
شرح مبسط وبسيط لمفهوم ال VLANAliMohammad155
 
11th session classes diagrams
11th session classes diagrams11th session classes diagrams
11th session classes diagramsAliMohammad155
 
Static route and rip and ospf
Static route and rip and ospfStatic route and rip and ospf
Static route and rip and ospfAliMohammad155
 
Ninth session software engineering sequence diagram
Ninth session software engineering sequence diagramNinth session software engineering sequence diagram
Ninth session software engineering sequence diagramAliMohammad155
 
Routers and packet tracer
Routers and packet tracerRouters and packet tracer
Routers and packet tracerAliMohammad155
 
Viii session activity diagram
Viii session activity diagramViii session activity diagram
Viii session activity diagramAliMohammad155
 
Seventh session functional and non functional requrements & usecase example
Seventh session functional and non functional requrements & usecase exampleSeventh session functional and non functional requrements & usecase example
Seventh session functional and non functional requrements & usecase exampleAliMohammad155
 
Sixth session software engineering usecase diagrams
Sixth session software engineering usecase diagramsSixth session software engineering usecase diagrams
Sixth session software engineering usecase diagramsAliMohammad155
 
fifth session in networking subnetmask and subnetting
fifth session in networking subnetmask and subnettingfifth session in networking subnetmask and subnetting
fifth session in networking subnetmask and subnettingAliMohammad155
 
functional requirements and non functional requirements
functional requirements and non functional requirementsfunctional requirements and non functional requirements
functional requirements and non functional requirementsAliMohammad155
 
fourth session of basics in networks
fourth session of basics in networksfourth session of basics in networks
fourth session of basics in networksAliMohammad155
 
Fourth session software engineering
Fourth session software engineeringFourth session software engineering
Fourth session software engineeringAliMohammad155
 
third session of basics in networks
third session of basics in networksthird session of basics in networks
third session of basics in networksAliMohammad155
 
Third session software engineering
Third session software engineeringThird session software engineering
Third session software engineeringAliMohammad155
 
Second session Networking (Network topology)
Second session Networking (Network topology)Second session Networking (Network topology)
Second session Networking (Network topology)AliMohammad155
 
Second session software engineering algorithms
Second session software engineering   algorithmsSecond session software engineering   algorithms
Second session software engineering algorithmsAliMohammad155
 

More from AliMohammad155 (20)

#1 الدرس الأول من دروس مسار تعلم ال SQL Server بعنوان مخطط ال ERD والتكامل ا...
#1  الدرس الأول من دروس مسار تعلم ال SQL Server بعنوان مخطط ال ERD والتكامل ا...#1  الدرس الأول من دروس مسار تعلم ال SQL Server بعنوان مخطط ال ERD والتكامل ا...
#1 الدرس الأول من دروس مسار تعلم ال SQL Server بعنوان مخطط ال ERD والتكامل ا...
 
شرح مبسط وبسيط لمفهوم ال VLAN
شرح مبسط وبسيط لمفهوم ال VLANشرح مبسط وبسيط لمفهوم ال VLAN
شرح مبسط وبسيط لمفهوم ال VLAN
 
11th session classes diagrams
11th session classes diagrams11th session classes diagrams
11th session classes diagrams
 
10th session erd
10th session erd10th session erd
10th session erd
 
Static route and rip and ospf
Static route and rip and ospfStatic route and rip and ospf
Static route and rip and ospf
 
Ninth session software engineering sequence diagram
Ninth session software engineering sequence diagramNinth session software engineering sequence diagram
Ninth session software engineering sequence diagram
 
Routers and packet tracer
Routers and packet tracerRouters and packet tracer
Routers and packet tracer
 
Viii session activity diagram
Viii session activity diagramViii session activity diagram
Viii session activity diagram
 
OSI Model
OSI ModelOSI Model
OSI Model
 
Seventh session functional and non functional requrements & usecase example
Seventh session functional and non functional requrements & usecase exampleSeventh session functional and non functional requrements & usecase example
Seventh session functional and non functional requrements & usecase example
 
Vlsm and flsm example
Vlsm and flsm exampleVlsm and flsm example
Vlsm and flsm example
 
Sixth session software engineering usecase diagrams
Sixth session software engineering usecase diagramsSixth session software engineering usecase diagrams
Sixth session software engineering usecase diagrams
 
fifth session in networking subnetmask and subnetting
fifth session in networking subnetmask and subnettingfifth session in networking subnetmask and subnetting
fifth session in networking subnetmask and subnetting
 
functional requirements and non functional requirements
functional requirements and non functional requirementsfunctional requirements and non functional requirements
functional requirements and non functional requirements
 
fourth session of basics in networks
fourth session of basics in networksfourth session of basics in networks
fourth session of basics in networks
 
Fourth session software engineering
Fourth session software engineeringFourth session software engineering
Fourth session software engineering
 
third session of basics in networks
third session of basics in networksthird session of basics in networks
third session of basics in networks
 
Third session software engineering
Third session software engineeringThird session software engineering
Third session software engineering
 
Second session Networking (Network topology)
Second session Networking (Network topology)Second session Networking (Network topology)
Second session Networking (Network topology)
 
Second session software engineering algorithms
Second session software engineering   algorithmsSecond session software engineering   algorithms
Second session software engineering algorithms
 

Recently uploaded

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformWSO2
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceIES VE
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxMarkSteadman7
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseWSO2
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 

Recently uploaded (20)

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 

Seventh session

  • 1. Arrays in Python Part || ‫إعداد‬: ‫م‬.‫محمد‬ ‫علي‬
  • 3. Sets  A set is a collection which is unordered and unindexed. In Python sets are written with curly brackets ({ })  Example:  set1 = {"apple", "banana", "cherry"} print(set1)  Note: Sets are unordered, so you cannot be sure in which order the items will appear.  set1 = {"apple", "banana", "cherry"} for x in set1: print(x)  Result: banana cherry apple
  • 4. Check if item in sets  print("banana" in set1)  Result: (True)  Change Item: Once a set is created, you cannot change its items, but you can add new items, by using add() method  set1 = {"apple", "banana", "cherry"} set1.add("orange") print(set1)  Result:  {'banana', 'cherry', 'apple', 'orange'}
  • 5. Change values in sets  Add multiple items to a set, using the update method  Example:  set1 = {"apple", "banana", "cherry"} set1.update(["orange", "mango", "grapes"]) print(set1)  Result: {'grapes', 'orange', 'mongo', 'apple', 'cherry', 'banana'}
  • 6. Deleted value from set  We can use remove(), discard() and pop()  remove(“item”): if the item not found will show an error  discard(“item”): if the item not found will not show an error  pop(): will remove the last item from set  Note: Sets are unordered, so when using the pop() method, you will not know which item that gets removed.  The clear() method empties the set  The del keyword will delete the set completely  So, clear() will delete the items from the set but del will delete set from the memory
  • 7. Join two sets  There are several ways to join two or more sets in Python.  We can use union() method returns a new set with all items from both sets example: set1 = {"a", "b" , "c"} set2 = {1, 2, 3} set3 = set1.union(set2) print(set3)  We can use update() method inserts the items in set2 into set1 example: set1 = {"a", "b" , "c"} set2 = {1, 2, 3} set1.update(set2) print(set1)  Note: both union() and update() will exclude any duplicate items.
  • 8. Set methods Method Description add() Adds an element to the set clear() Removes all the elements from the set copy() Returns a copy of the set difference() Returns a set containing the difference between two or more sets difference_update() Removes the items in this set that are also included in another, specified set discard() Remove the specified item intersection() Returns a set, that is the intersection of two other sets intersection_update() Removes the items in this set that are not present in other, specified set(s) isdisjoint() Returns whether two sets have a intersection or not
  • 9. Set methods cont  issubset() Returns whether another set contains this set or not  issuperset() Returns whether this set contains another set or not  pop() Removes an element from the set  remove() Removes the specified element  symmetric_difference() Returns a set with the symmetric differences of two sets  symmetric_difference_update() inserts the symmetric differences from this set and another  union() Return a set containing the union of sets  update() Update the set with the union of this set and others
  • 10. Dictionaries  A dictionary is a collection which is unordered, changeable and indexed. In Python dictionaries are written with curly brackets, and they have keys and values.  Example: thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } print(thisdict) Result: {'brand': 'Ford', 'model': 'Mustang', 'year': 1964}
  • 11. Get an item  You can access the items of a dictionary by referring to its key name, inside square brackets  Example: x = thisdict["model"] Print(x) Result: Mustang  There is also a method called get() will give the same result x = thisdict.get(“model”) Print(x) Result: Mustang
  • 12. Change values  You can change the value of a specific item by referring to its key name  Example:  thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } thisdict["year"] = 2020  This example will change the year to 2020
  • 13. Loops over dictionaries  The following will give all key names in dictionary: for x in thisdict: print(x)  The following will give all values names in dictionary: for x in thisdict: print(thisdict[x])  We can also use values() function to return values of a dictionary for x in thisdict.values(): print(x)  To get both of key and values we use items() method: for x, y in thisdict.items(): print(x, y)  X for the key and y for the value
  • 14. Check for items in dictionaries  if "model" in thisdict: print("Yes, 'model' is one of the keys in the thisdict dictionary")  To add item to dictionary we use the following: thisdict["color"] = "red" print(thisdict)  Result: {'brand': 'Ford', 'model': 'Mustang', 'year': 2020, 'color': 'red'}
  • 15. Removing items  We can use pop(),popitem(),clear() method and del keyword  pop(“item”): remove specific key name  popitem(): will remove the last key, in python 3.7 will remove a random item  The del keyword can delete the dictionary completely del thisdict  The clear() method empties the dictionary
  • 16. Copy the dictionaries  If we write dict2=dict1, in this way dict2 will be a reference for dict1 and any change on dict1 will happened the same change on dict2  There are ways to make a copy, one way is to use the built-in Dictionary method copy() mydict = thisdict.copy()  Another way to make a copy is to use the built-in method mydict = dict(thisdict)
  • 17. Nested Dictionaries  A dictionary can also contain many dictionaries, this is called nested dictionaries  Example myfamily = { "child1" : { "name" : “Ali", "year" : 1995 }, "child2" : { "name" : “Ghadeer", "year" : 1994 }, "child3" : { "name" : “Mohammad", "year" : 1996 } }
  • 18. Nested Dictionaries  Create three dictionaries, than create one dictionary that will contain the other three dictionaries  child1 = { "name" : “Ali", "year" : 1995 } child2 = { "name" : “Ghadeer", "year" : 1994 } child3 = { "name" : “Mohammad", "year" : 1996 } myfamily = { "child1" : child1, "child2" : child2, "child3" : child3 }
  • 19. Dictionary Methods Method Description clear() Removes all the elements from the dictionary copy() Returns a copy of the dictionary fromkeys() Returns a dictionary with the specified keys and value get() Returns the value of the specified key items() Returns a list containing a tuple for each key value pair keys() Returns a list containing the dictionary's keys pop() Removes the element with the specified key popitem() Removes the last inserted key-value pair setdefault() Returns the value of the specified key. If the key does not exist: insert the key, with the specified value update() Updates the dictionary with the specified key-value pairs values() Returns a list of all the values in the dictionary