I have a list that contains tuples in the form:
[('s1', 's2'),('s3','s32')...('s2','s1')]`
How can I count the number of distinct tuples, considering that the order is not important?
Example: ('s1','s2')
is the same as ('s2','s1')
I have a list that contains tuples in the form:
[('s1', 's2'),('s3','s32')...('s2','s1')]`
How can I count the number of distinct tuples, considering that the order is not important?
Example: ('s1','s2')
is the same as ('s2','s1')
Using
collections.Counter
andfrozenset
:To get keys as tuples:
Using frozenset to normalize your distinct tuples. And then checking the amount of items in the resulting set: