Skip to content

Instantly share code, notes, and snippets.

@Aaron1011
Last active December 10, 2015 10:49
Show Gist options
  • Save Aaron1011/4423616 to your computer and use it in GitHub Desktop.
Save Aaron1011/4423616 to your computer and use it in GitHub Desktop.
Find intersection
def intersection(sets):
counts = {}
for s in sets:
print "Starting set"
if not counts:
for item in s:
counts[item] = 1
continue
changed = False
for item in s:
if item in counts:
changed = True
counts[item] += 1
if not changed:
return set()
for key in counts.copy():
if counts[key] is not len(sets):
del counts[key]
return counts.keys()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment