On Fri, Dec 16, 2011 at 12:11 AM, Ian Kelly <ian.g.ke...@gmail.com> wrote: > On Thu, Dec 15, 2011 at 11:30 PM, Alec Taylor <alec.tayl...@gmail.com> wrote: >> Just for fun, use the Hungarian Algorithm >> >> (Python implementation: http://software.clapper.org/munkres/) > > That's a pretty silly approach, but okay: > > def listequals(a, b): > if len(a) != len(b): > return False > matrix = [[int(item_a != item_b) for item_b in b] for item_a in a] > path = Munkres().compute(matrix) > return sum(matrix[r][c] for (r, c) in path) == 0
Amendment -- it seems that Hungarian implementation fails on an empty matrix: def listequals(a, b): if len(a) == len(b) == 0: return True if len(a) != len(b): return False matrix = [[int(item_a != item_b) for item_b in b] for item_a in a] path = Munkres().compute(matrix) return sum(matrix[r][c] for (r, c) in path) == 0 -- http://mail.python.org/mailman/listinfo/python-list