I have 3 variable length lists of sets. I need to find the common elements in each list (across sets) really really quickly.
Here is some sample code: # Doesn't make sense to union the sets - we're going to do intersections later anyway l1 = reduce(operator.add, list(x) for x in l1) l2 = reduce(operator.add, list(x) for x in l2) l3 = reduce(operator.add, list(x) for x in l3) # Should I do this in two steps? Maybe by intersecting the two shortest lists first? s = frozenset(l1) & frozenset(l2) & frozenset(l3) I'm assuming frozensets are (somehow) quicker than sets because they're immutable. Any code suggestions? Maybe using something in the new fancy-schmancy itertools module? Thanks, Prateek -- http://mail.python.org/mailman/listinfo/python-list