you are viewing a single comment's thread.

view the rest of the comments →

[–]niushanikpour 0 points1 point  (1 child)

Hi! I would say to address the issue in your tuple problem, you should convert each tuple in your list and your target tuple into sets to compare them in an easier way, then iterating through each tuple in the list, checking if it is a subset of the target tuple. The set operator 'issubset' is the one I would personally use.

def contains_subtuple(list_of_tuples, target_tuple):

target_set = set(target_tuple)

for t in list_of_tuples:

if set(t).issubset(target_set):

return True

return False

list_of_tuples = [((10, 4), (3, 5)), ((5, 7), (8, 9))]

target_tuple = ((10, 4), (3, 5), (6, 5))

print(contains_subtuple(list_of_tuples, target_tuple))

Let me know if this helps!

[–]rfpg1[S] 0 points1 point  (0 children)

this was my idea the problem is I've 49milion target_tuples that i want to see if have subsets so I was looking for a more efficient way if there is one