SlideShare una empresa de Scribd logo
1 de 18
Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
Typing Speed
Week

Target

Achieved

1

25

23

2

30

26

3

30

28

4

35

32

5

40

38
Jobs Applied
#

Company

Designation

Applied Date

1
2
3

Aug 24

Current
Status
Sets in python
shafeeque
●

shafeequemonp@gmail.com

●

www.facebook.com/shafeequemonppambodan

●

twitter.com/shafeequemonp

●

in.linkedin.com/in/shafeequemonp

●

9809611325
Sets:
●

●

●

A set is an unordered collection of objects, unlike sequence objects such as lists and
tuples
Sets cannot have duplicate members - a given object appears in a set 0 or 1 times
All members of a set have to be hashable, just like dictionary keys

●

Integers, floating point numbers, tuples, and strings are hashable
process

●

dictionaries, lists, and other sets (except frozensets) are not.

●

Eg:

set(['b', 'e', 'o', 's', 'u', 't'])
set([32, 26, 12, 54])
Constructing Sets:
One way to construct sets is by passing any sequential object to the "set"
constructor

●

>>> set([0, 1, 2, 3])
set([0, 1, 2, 3])
>>> set("obtuse")
set(['b', 'e', 'o', 's', 'u', 't'])

●

Add elements to sets
>>> s = set([12, 26, 54])
>>> s.add(32)
>>> s
set([32, 26, 12, 54])
●

Update set:
>>> s.update([26, 12, 9, 14])
>>> s
set([32, 9, 12, 14, 54, 26])

●

Copy set:
●

The set function also provides a copy constructor. However, remember that the copy
constructor will copy the set, but not the individual elements
>>> s2 = s.copy()
>>> s2
set([32, 9, 12, 14, 54, 26])
Membership Testing:
●

We can check if an object is in the set using the same "in" operator as with
sequential data types
>>> 32 in s
True
>>> 6 in s
False
>>> 6 not in s
True

●

We can also test the membership of entire sets. Given two sets s1 and s2 , we
check if s1 is a subset or a superset of s2
>>> s.issubset(set([32, 8, 9, 12, 14, -4, 54, 26, 19]))
True
>>> s.issuperset(set([9, 12]))
True
●

Note that the <= and >= operators also express the issubset and issuperset functions
respectively.
>>> set([4, 5, 7]) <= set([4, 5, 7, 9])
True
>>> set([9, 12, 15]) >= set([9, 12])
True

Removing Items:
●

●

There are three functions which remove individual items from a set, called pop,
remove, and discard
The first, pop, simply removes an item from the set
>>> s = set([1,2,3,4,5,6])
>>> s.pop()
1
>>> s
set([2,3,4,5,6])
●

We also have the "remove" function to remove a specified element.
>>> s.remove(3)
>>> s
set([2,4,5,6])
●

However, removing a item which isn't in the set causes an error.
>>> s.remove(9)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
KeyError: 9

●

We also have another operation for removing elements from a set,
clear, which simply removes all elements from the set
>>> s.clear()
>>> s
set([])
Iteration Over Sets:
●

We can also have a loop move over each of the items in a set.

●

However, since sets are unordered, it is undefined which order the iteration will follow.
>>> s = set("blerg")
>>> for n in s:
...

print n,

...
rbelg
Set Operations:
●

Python allows us to perform all the standard mathematical set operations,
using members of set
●

Union
The union is the merger of two sets. Any element in s1 or s2 will appear
in their union
>>> s1 = set([4, 6, 9])
>>> s2 = set([1, 6, 8])
>>> s1.union(s2)
set([1, 4, 6, 8, 9])
>>> s1 | s2
set([1, 4, 6, 8, 9])
●

Intersection
●

Any element which is in both s1 and s2 will appear in their intersection
>>> s1 = set([4, 6, 9])
>>> s2 = set([1, 6, 8])
>>> s1.intersection(s2)
set([6])
>>> s1 & s2
set([6])
>>> s1.intersection_update(s2)
>>> s1
set([6])

●

Symmetric Difference
●

The symmetric difference of two sets is the set of elements which
are in one of either set, but not in both
>>> s1 = set([4, 6, 9])
>>> s2 = set([1, 6, 8])
>>> s1.symmetric_difference(s2)
set([8, 1, 4, 9])
>>> s1 ^ s2
set([8, 1, 4, 9])
>>> s1.symmetric_difference_update(s2)
>>> s1
set([8, 1, 4, 9])
Set Difference

●

●

Python can also find the set difference of s1 and s2 , which is the elements that
are in s1 but not in s2.
>>> s1 = set([4, 6, 9])
>>> s2 = set([1, 6, 8])
>>> s1.difference(s2)
set([9, 4])
>>> s1 - s2
set([9, 4])
>>> s1.difference_update(s2)
>>> s1
set([9, 4])

Multiple sets:
●

Starting with Python 2.6, "union", "intersection", and "difference" can work with
multiple input by using the set constructor. For example,
>>> s1 = set([3, 6, 7, 9])
>>> s2 = set([6, 7, 9, 10])
>>> s3 = set([7, 9, 10, 11])
>>> set.intersection(s1, s2, s3)
set([9, 7])
Frozenset:
●

●

●

A frozenset is basically the same as a set, except that it is immutable once it is created, its members cannot be changed
Since they are immutable, they are also hashable, which means that
frozensets can be used as members in other sets and as dictionary keys
frozensets have the same functions as normal sets, except none of the
functions that change the contents (update, remove, pop, etc.) are
available
>>> fs = frozenset([2, 3, 4])
>>> s1 = set([fs, 4, 5, 6])
>>> s1
set([4, frozenset([2, 3, 4]), 6, 5])
>>> fs.intersection(s1)
frozenset([4])
>>> fs.add(6)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'frozenset' object has no attribute
'add'
If this presentation helped you, please visit our page facebook.com/baabtra and
like it.

Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550

Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com

NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

List in Python
List in PythonList in Python
List in Python
 
Tuples in Python
Tuples in PythonTuples in Python
Tuples in Python
 
Python tuple
Python   tuplePython   tuple
Python tuple
 
Tuple in python
Tuple in pythonTuple in python
Tuple in python
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
 
Java Stack Data Structure.pptx
Java Stack Data Structure.pptxJava Stack Data Structure.pptx
Java Stack Data Structure.pptx
 
Python list
Python listPython list
Python list
 
Lists
ListsLists
Lists
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
 
Python strings
Python stringsPython strings
Python strings
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
 
Python for loop
Python for loopPython for loop
Python for loop
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
Dictionaries in Python
Dictionaries in PythonDictionaries in Python
Dictionaries in Python
 
Arrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaArrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | Edureka
 
Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 

Similar a Sets in python

UNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllegeUNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllege
Ramanamurthy Banda
 
UNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllegeUNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllege
Ramanamurthy Banda
 
Developers' New features of Sql server express 2012
Developers' New features of Sql server express 2012Developers' New features of Sql server express 2012
Developers' New features of Sql server express 2012
Ziaur Rahman
 

Similar a Sets in python (20)

C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 
Slicing in Python - What is It?
Slicing in Python - What is It?Slicing in Python - What is It?
Slicing in Python - What is It?
 
Python lecture 05
Python lecture 05Python lecture 05
Python lecture 05
 
Queue
QueueQueue
Queue
 
Very basic functional design patterns
Very basic functional design patternsVery basic functional design patterns
Very basic functional design patterns
 
Pythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptxPythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptx
 
Insert Sort & Merge Sort Using C Programming
Insert Sort & Merge Sort Using C ProgrammingInsert Sort & Merge Sort Using C Programming
Insert Sort & Merge Sort Using C Programming
 
Introduction To Programming with Python
Introduction To Programming with PythonIntroduction To Programming with Python
Introduction To Programming with Python
 
Effective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyEffective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPy
 
BA lab1.pptx
BA lab1.pptxBA lab1.pptx
BA lab1.pptx
 
UNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllegeUNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllege
 
UNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllegeUNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllege
 
Developers' New features of Sql server express 2012
Developers' New features of Sql server express 2012Developers' New features of Sql server express 2012
Developers' New features of Sql server express 2012
 
Talk on Standard Template Library
Talk on Standard Template LibraryTalk on Standard Template Library
Talk on Standard Template Library
 
Arrays 06.ppt
Arrays 06.pptArrays 06.ppt
Arrays 06.ppt
 
Python lab basics
Python lab basicsPython lab basics
Python lab basics
 
07+08slide.pptx
07+08slide.pptx07+08slide.pptx
07+08slide.pptx
 
Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303
 
07012023.pptx
07012023.pptx07012023.pptx
07012023.pptx
 

Más de baabtra.com - No. 1 supplier of quality freshers

Más de baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

Último

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
heathfieldcps1
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Último (20)

psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
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Ữ Â...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
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
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
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
 
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
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
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
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
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.
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 

Sets in python

  • 1.
  • 2. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 6. Sets: ● ● ● A set is an unordered collection of objects, unlike sequence objects such as lists and tuples Sets cannot have duplicate members - a given object appears in a set 0 or 1 times All members of a set have to be hashable, just like dictionary keys ● Integers, floating point numbers, tuples, and strings are hashable process ● dictionaries, lists, and other sets (except frozensets) are not. ● Eg: set(['b', 'e', 'o', 's', 'u', 't']) set([32, 26, 12, 54])
  • 7. Constructing Sets: One way to construct sets is by passing any sequential object to the "set" constructor ● >>> set([0, 1, 2, 3]) set([0, 1, 2, 3]) >>> set("obtuse") set(['b', 'e', 'o', 's', 'u', 't']) ● Add elements to sets >>> s = set([12, 26, 54]) >>> s.add(32) >>> s set([32, 26, 12, 54])
  • 8. ● Update set: >>> s.update([26, 12, 9, 14]) >>> s set([32, 9, 12, 14, 54, 26]) ● Copy set: ● The set function also provides a copy constructor. However, remember that the copy constructor will copy the set, but not the individual elements >>> s2 = s.copy() >>> s2 set([32, 9, 12, 14, 54, 26])
  • 9. Membership Testing: ● We can check if an object is in the set using the same "in" operator as with sequential data types >>> 32 in s True >>> 6 in s False >>> 6 not in s True ● We can also test the membership of entire sets. Given two sets s1 and s2 , we check if s1 is a subset or a superset of s2 >>> s.issubset(set([32, 8, 9, 12, 14, -4, 54, 26, 19])) True >>> s.issuperset(set([9, 12])) True
  • 10. ● Note that the <= and >= operators also express the issubset and issuperset functions respectively. >>> set([4, 5, 7]) <= set([4, 5, 7, 9]) True >>> set([9, 12, 15]) >= set([9, 12]) True Removing Items: ● ● There are three functions which remove individual items from a set, called pop, remove, and discard The first, pop, simply removes an item from the set >>> s = set([1,2,3,4,5,6]) >>> s.pop() 1 >>> s set([2,3,4,5,6])
  • 11. ● We also have the "remove" function to remove a specified element. >>> s.remove(3) >>> s set([2,4,5,6]) ● However, removing a item which isn't in the set causes an error. >>> s.remove(9) Traceback (most recent call last): File "<stdin>", line 1, in ? KeyError: 9 ● We also have another operation for removing elements from a set, clear, which simply removes all elements from the set >>> s.clear() >>> s set([])
  • 12. Iteration Over Sets: ● We can also have a loop move over each of the items in a set. ● However, since sets are unordered, it is undefined which order the iteration will follow. >>> s = set("blerg") >>> for n in s: ... print n, ... rbelg
  • 13. Set Operations: ● Python allows us to perform all the standard mathematical set operations, using members of set ● Union The union is the merger of two sets. Any element in s1 or s2 will appear in their union >>> s1 = set([4, 6, 9]) >>> s2 = set([1, 6, 8]) >>> s1.union(s2) set([1, 4, 6, 8, 9]) >>> s1 | s2 set([1, 4, 6, 8, 9])
  • 14. ● Intersection ● Any element which is in both s1 and s2 will appear in their intersection >>> s1 = set([4, 6, 9]) >>> s2 = set([1, 6, 8]) >>> s1.intersection(s2) set([6]) >>> s1 & s2 set([6]) >>> s1.intersection_update(s2) >>> s1 set([6]) ● Symmetric Difference ● The symmetric difference of two sets is the set of elements which are in one of either set, but not in both >>> s1 = set([4, 6, 9]) >>> s2 = set([1, 6, 8]) >>> s1.symmetric_difference(s2) set([8, 1, 4, 9]) >>> s1 ^ s2 set([8, 1, 4, 9]) >>> s1.symmetric_difference_update(s2) >>> s1 set([8, 1, 4, 9])
  • 15. Set Difference ● ● Python can also find the set difference of s1 and s2 , which is the elements that are in s1 but not in s2. >>> s1 = set([4, 6, 9]) >>> s2 = set([1, 6, 8]) >>> s1.difference(s2) set([9, 4]) >>> s1 - s2 set([9, 4]) >>> s1.difference_update(s2) >>> s1 set([9, 4]) Multiple sets: ● Starting with Python 2.6, "union", "intersection", and "difference" can work with multiple input by using the set constructor. For example, >>> s1 = set([3, 6, 7, 9]) >>> s2 = set([6, 7, 9, 10]) >>> s3 = set([7, 9, 10, 11]) >>> set.intersection(s1, s2, s3) set([9, 7])
  • 16. Frozenset: ● ● ● A frozenset is basically the same as a set, except that it is immutable once it is created, its members cannot be changed Since they are immutable, they are also hashable, which means that frozensets can be used as members in other sets and as dictionary keys frozensets have the same functions as normal sets, except none of the functions that change the contents (update, remove, pop, etc.) are available >>> fs = frozenset([2, 3, 4]) >>> s1 = set([fs, 4, 5, 6]) >>> s1 set([4, frozenset([2, 3, 4]), 6, 5]) >>> fs.intersection(s1) frozenset([4]) >>> fs.add(6) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'frozenset' object has no attribute 'add'
  • 17. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  • 18. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550

Notas del editor

  1. &lt;number&gt;
  2. &lt;number&gt;
  3. &lt;number&gt;
  4. &lt;number&gt;
  5. &lt;number&gt;