A slightly faster version of the implementation (if you know that most lists of pairs will have different lengths):
def checkEqual(L1, L2): return len(L1) == len(L2) and sorted(L1) == sorted(L2)
Comparison:
>>> timeit(lambda: sorting([1,2,3], [3,2,1])) 2.42745304107666 >>> timeit(lambda: lensorting([1,2,3], [3,2,1])) 2.5644469261169434 # speed down not much (for large lists the difference tends to 0) >>> timeit(lambda: sorting([1,2,3], [3,2,1,0])) 2.4570400714874268 >>> timeit(lambda: lensorting([1,2,3], [3,2,1,0])) 0.9596951007843018 # speed up
defuz Oct 10 '12 at 7:13 2012-10-10 07:13
source share