How to find the intersection of two tuples in Python

2 Answers

0 votes
tpl1 = (3, 7, 9, 0, 2, 1)
tpl2 = (2, 8, 6, 3)

intersection = tuple(set(tpl1) & set(tpl2))

print(intersection)



'''
run:

(2, 3)

'''

 



answered Nov 26, 2022 by avibootz
0 votes
tpl1 = ((0, 1), (2, 1), (3, 4), (9, 5), (7, 8))
tpl2 = ((9, 1), (7, 8), (3, 4), (0, 6), (7, 8))

intersection = tuple(set(tpl1) & set(tpl2))

print(intersection)



'''
run:

((3, 4), (7, 8))

'''

 



answered Nov 26, 2022 by avibootz

Related questions

4 answers 281 views
1 answer 164 views
1 answer 175 views
1 answer 229 views
3 answers 177 views
1 answer 146 views
...