test for list equality
Ian Kelly
ian.g.kelly at gmail.com
Fri Dec 16 02:11:10 EST 2011
On Thu, Dec 15, 2011 at 11:30 PM, Alec Taylor <alec.taylor6 at 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
More information about the Python-list
mailing list