Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python Frozenset operations

# Frozensets
# initialize A , B
 and C
A = frozenset([4, 3, 2, 1])
B = frozenset([7, 6, 5, 4])
C = frozenset([5, 4])

# copy
D = A.copy()
print("Copy of frozen set: ", D)

# union
print("Union of frozen set: ", A.union(B)) 

# intersection
print("Intersection of frozen set: ", A.intersection(B)) 

# difference
print("Difference of frozen set: ", A.difference(B))  

# symmetric_difference
print("symmetric_difference of frozen set: ", A.symmetric_difference(B))  

# isdisjoint() method
print("disjoint of frozen set: ", A.isdisjoint(C))

# issubset() method
print("subset of frozen set: ", C.issubset(B))
Comment

Python frozenset()

Frozen set is just an immutable version of a Python set object. While elements of a set
can be modified at any time,elements of the frozen set remain the same after creation.
frozenset([iterable])
# tuple of vowels
vowels = ('a', 'e', 'i', 'o', 'u')

fSet = frozenset(vowels)
print('The frozen set is:', fSet)  #The frozen set is: frozenset({'a', 'o', 'u', 'i', 'e'})

print('The empty frozen set is:', frozenset())   #The empty frozen set is: frozenset()

# frozensets are immutable
fSet.add('v')
Comment

Syntax of Python Frozenset

frozenset(iterable_object_name)
Comment

Python Frozenset

# Frozensets
# initialize A and B
A = frozenset([1, 2, 3, 4])
B = frozenset([3, 4, 5, 6])
Comment

Python Frozenset

# tuple of vowels
numbers = ('1', '2', '3', '4', '5')
set = frozenset(numbers)
print('The frozen set is:', set)
print('The empty frozen set is:', frozenset())

# frozensets are immutable
set.add('6')
Comment

PREVIOUS NEXT
Code Example
Python :: -2 in python 
Python :: prettify json in pycharm 
Python :: time series python 
Python :: python port forwarding 
Python :: pandas previous row 
Python :: example exponential distribution python 
Python :: pathlib change extension 
Python :: receipt data extraction python 
Python :: pong code python 
Python :: python anonymous object 
Python :: editing specific line in text file in python 
Python :: Can there be an if statement inside an if statement python 
Python :: pandas extracting tables from pdf 
Python :: python sched 
Python :: data.head on terminal 
Python :: discord.py 8ball 
Python :: harihar kaka class 10 questions 
Python :: random module 
Python :: findout age in python 
Python :: pyevtk documentation writearraystovtk 
Python :: how to modify name of email from divi 
Python :: derivative of multivariable function pytorch 
Shell :: uninstall libreoffice ubuntu 
Shell :: git store credential 
Shell :: dotnet ef scaffold sqlite 
Shell :: apache2.service is not active cannot reload. ubuntu 
Shell :: Wrong permissions on configuration file, should not be world writable! 
Shell :: how to pronounce ubuntu 
Shell :: cmd clear dns cache 
Shell :: nvm ubuntu 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =