Answers for "add list to set python"

6

add list to set python

set.update() or |=

>>> a = set('abc')
>>> l = ['d', 'e']
>>> a.update(l)
>>> a
{'e', 'b', 'c', 'd', 'a'}

>>> l = ['f', 'g']
>>> a |= set(l)
>>> a
{'e', 'b', 'f', 'c', 'd', 'g', 'a'}
Posted by: Guest on August-25-2020
11

add element in set python

thisset = {"apple", "banana", "cherry"}

thisset.add("orange")

print(thisset)
Posted by: Guest on May-17-2020

Python Answers by Framework

Browse Popular Code Answers by Language