Created
March 5, 2010 15:46
-
-
Save rmax/322839 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
#!/usr/bin/env python | |
# -*- coding: UTF-8 -*- | |
def getitem(l, index, default=None): | |
"""Returns value of index or default""" | |
try: | |
return l[index] | |
except IndexError: | |
return default | |
def clean(l1, l2): | |
"""Removes common elements from both lists""" | |
shortest, longest = (l1, l2) if len(l1) < len(l2) else (l2, l1) | |
def remove(l): | |
shortest.remove(l) | |
longest.remove(l) | |
map(remove, (l for l in longest if l in shortest)) | |
if __name__ == '__main__': | |
L1 = [[1, 1, 2], [2, 3, 5], [3, 2, 8]] | |
L2 = [[2, 1, 6], [3, 2, 8], [1, 3, 5], [4, 4, 7]] | |
clean(L1, L2) | |
for i in range(max(len(L1), len(L2))): | |
a = getitem(L1, i, []) | |
b = getitem(L2, i, []) | |
diff = [j for j in range(max(len(a), len(b))) | |
if not getitem(a, j) == getitem(b, j)] | |
print a, b, diff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment