-
-
Save czheo/37710f057af62c4d8933bbb8cad98b7d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
l = [("a", "b"), ("b", "c"), ("e", "f")] | |
def merge(l): | |
ret = [] | |
for s in map(set, l): | |
for x in ret: | |
if s & x: | |
x.update(s) | |
break | |
else: | |
ret.append(s) | |
return ret | |
print(merge(l)) | |
# [{'b', 'c', 'a'}, {'f', 'e'}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment