Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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'}
Comment

PREVIOUS NEXT
Code Example
Python :: dataframe nested json 
Python :: pep full form 
Python :: Prime numbers within given range in python 
Python :: iterate through attributes of class python 
Python :: pandas delete spaces 
Python :: how to select python 3 interpreter in linux 
Python :: python decimal string 
Python :: TypeError: cannot unpack non-iterable int object 
Python :: Python Creating string from a timestamp 
Python :: df only take 2 columns 
Python :: get one from dataloader 
Python :: sang nguyen to python 
Python :: console.log() python 
Python :: how to make a pause in python 
Python :: python is float 
Python :: time a line of code python 
Python :: remove element from list python 
Python :: python check if two sets intersect 
Python :: numpy roundup to nearest 5 
Python :: convert index of a pandas dataframe into a column 
Python :: Django less than and greater than 
Python :: find common values in different dataframes pandas 
Python :: how to iterate over rows in a dataframe in pandas 
Python :: shutil move file 
Python :: change size of plot python 
Python :: how to create a tuple from csv python 
Python :: api testing with python 
Python :: python3 strip punctuation from string 
Python :: how to round off values in columns in pandas in excel 
Python :: how to make getter in python 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =