I had a list like
[(1, 2), (2, 3), (3, 2), (3, 4), (4, 1), (4, 3)]
which means user 1 follow user 2 and so on...
The goal is to find a list like
[(2, 3), (3,4)]
which means user 2 followed user 3 and vice verse.
So far, I had came up one way which I think is still not fast enough ( written in Python )
[x for x, y in collections.Counter([tuple(sorted(x)) for x in l]).iteritems() if y > 1]
Can anyone show me some faster algorithm ?
[(2, 3), (3,4)]
mean user 3 follows user 2?(2,3)
and(3,2)
the result got(2,3)
; same for(3,4)
(3, 4)
is a separate result. The description seems to imply that the(2, 3)
means 2 follows 3 and the(3, 4)
means 3 follows 2.