Update Set Python
set = {'a', 'b'}
other_set = {1, 2, 3}
# Update set with elements of other set
# update method returns None
set.update(other_set)
print('set =', set) # set = {1, 2, 3, 'a', 'b'}
'''
Below, process of adding elements of
string and dictionary to a set is illustrated
'''
str = 'abc'
set = {1, 2}
# Add elements of string to set
set.update(str)
print('set =', set) # set = {1, 2, 'c', 'b', 'a'}
set = {'a', 'b'}
dictionary = {'key': 1, 'lock': 2}
# Add keys of dictionary to set
set.update(dictionary)
print('set =', set) # set = {'key', 'lock', 'a', 'b'}
Wissam