How to create a set with all the elements contain in two sets in Python

2 Answers

0 votes
st1 = {"a", "b", "c", "x"}
st2 = {"a", "d", "e", "x", "f", "g"}

st = st1.intersection(st2)

print(st)


'''
run:

{'a', 'x'}

'''

 



answered Dec 11, 2017 by avibootz
0 votes
st1 = {"a", "b", "c", "x"}
st2 = {"a", "d", "e", "x", "f", "g"}

st = st1 & st2

print(st)


'''
run:

{'a', 'x'}

'''

 



answered Dec 11, 2017 by avibootz

Related questions

2 answers 238 views
1 answer 168 views
2 answers 158 views
1 answer 134 views
1 answer 163 views
3 answers 206 views
206 views asked Apr 24, 2021 by avibootz
...