Given input:
[('is','my','order'), ('my','order', 'is'), ('temp', 'ques'), ('ques','temp')]
Desired output:
[('is','my','order'), ('temp', 'ques')]
In the output, the order of the tuple or the order of the contents of tuple doesn't matter.
Given input:
[('is','my','order'), ('my','order', 'is'), ('temp', 'ques'), ('ques','temp')]
Desired output:
[('is','my','order'), ('temp', 'ques')]
In the output, the order of the tuple or the order of the contents of tuple doesn't matter.
Because for you order doesn't matter, you can use set to achieve this:
>>> input_list = [('is','my','order'), ('my','order', 'is'), ('temp', 'ques'), ('ques','temp')]
>>> set(tuple(sorted(l)) for l in input_list)
set([('ques', 'temp'), ('is', 'my', 'order')])
Firstly sort the content of each nested tuple to ensure your set considers tuples with common items as same. Then I am type-casting it again to tuple because sorted returns list which are unhashable. Finally, set removes duplicate entries of your tuples.
Please refer "set" documentation for more details.
You can sort each of the sublists and then add them to a list, dropping all duplicates
output_list = []
for tup in map(sorted, tuple_list):
if tup not in output_list:
output_list.append(tup)
print(output_list)
mytuples = [('one','two'), ('two','one)]
myset=set()
for x in mytuples:
myset.update(x)
print(myset)
output {'two', 'one'}
this will give you a set of all the unique values in your dataset. maybe not helpful
so you may have to check each tuple against every other tuple with the same length assuming you want to keep the tuple structure