For example, I want to check every elements in tuple (1, 2) are in tuple (1, 2, 3, 4, 5). I don't think use loop is a good way to do it, I think it could be done in one line.
(1, 2)
(1, 2, 3, 4, 5)
You can use set.issubset or set.issuperset to check if every element in one tuple or list is in other.
set.issubset
set.issuperset
>>> tuple1 = (1, 2) >>> tuple2 = (1, 2, 3, 4, 5) >>> set(tuple1).issubset(tuple2) True >>> set(tuple2).issuperset(tuple1) True
2.1m questions
2.1m answers
60 comments
57.0k users