Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Fixed list mutation problems.
Source Link
xnor
  • 149.6k
  • 26
  • 287
  • 676

Python 2, 9094 bytes

defg=lambda f(a,bc,p=[])*p:c=id(lambda a),id(b);r=c:c in p;p+=c,;return rp or a>[]<b and all(map(fg((id(a),id(b)),c,*p),a,b))orif a>[]<b else a==b
g(0)

Try it online! Try it online!

An improvement on isaacg's very clever solution of storing the id pairs of lists being processed and declaring them equal if the same comparison comes up on a lower level.

The recursive step all(map(f...,a,b)) says that a and b are equal if all corresponding pair of elements in them are equal. This works nicely to reject unequal-length because map pads the shortest list with None, unlike zip which truncates. Since none of the actual lists contain None, these padded lists will always be rejected.

Python 2, 90 bytes

def f(a,b,p=[]):c=id(a),id(b);r=c in p;p+=c,;return r or a>[]<b and all(map(f,a,b))or a==b

Try it online!

An improvement on isaacg's very clever solution of storing the id pairs of lists being processed and declaring them equal if the same comparison comes up on a lower level.

The recursive step all(map(f,a,b)) says that a and b are equal if all corresponding pair of elements in them are equal. This works nicely to reject unequal-length because map pads the shortest list with None, unlike zip which truncates. Since none of the actual lists contain None, these padded lists will always be rejected.

Python 2, 94 bytes

g=lambda c,*p:lambda a,b:c in p or all(map(g((id(a),id(b)),c,*p),a,b))if a>[]<b else a==b
g(0)

Try it online!

An improvement on isaacg's very clever solution of storing the id pairs of lists being processed and declaring them equal if the same comparison comes up on a lower level.

The recursive step all(map(...,a,b)) says that a and b are equal if all corresponding pair of elements in them are equal. This works nicely to reject unequal-length because map pads the shortest list with None, unlike zip which truncates. Since none of the actual lists contain None, these padded lists will always be rejected.

added 345 characters in body
Source Link
xnor
  • 149.6k
  • 26
  • 287
  • 676

Python 2, 90 bytes

def f(a,b,p=[]):c=id(a),id(b);r=c in p;p+=c,;return r or a>[]<b and all(map(f,a,b))or a==b

Try it online!

An improvement on isaacg's very clever solution of storing the id pairs of lists being processed and declaring them equal if the same comparison comes up on a lower level.

The recursive step all(map(f,a,b)) says that a and b are equal if all corresponding pair of elements in them are equal. This works nicely to reject unequal-length because map pads the shortest list with None, unlike zip which truncates. Since none of the actual lists contain None, these padded lists will always be rejected.

Python 2, 90 bytes

def f(a,b,p=[]):c=id(a),id(b);r=c in p;p+=c,;return r or a>[]<b and all(map(f,a,b))or a==b

Try it online!

An improvement on isaacg's very clever solution of storing the id pairs of lists being processed and declaring them equal if the same comparison comes up on a lower level.

Python 2, 90 bytes

def f(a,b,p=[]):c=id(a),id(b);r=c in p;p+=c,;return r or a>[]<b and all(map(f,a,b))or a==b

Try it online!

An improvement on isaacg's very clever solution of storing the id pairs of lists being processed and declaring them equal if the same comparison comes up on a lower level.

The recursive step all(map(f,a,b)) says that a and b are equal if all corresponding pair of elements in them are equal. This works nicely to reject unequal-length because map pads the shortest list with None, unlike zip which truncates. Since none of the actual lists contain None, these padded lists will always be rejected.

added 38 characters in body
Source Link
xnor
  • 149.6k
  • 26
  • 287
  • 676

Python 2, 9190 bytes

def f(a,b,p=[]):c=id(a),id(b);r=c in p;p+=c,;return r or a>[]<b and all(map(f,a,b))if a>[]<b elseor a==b

Try it online! Try it online!

An improvement on isaacg's very clever solution of storing the id pairs of lists being processed and declaring them equal if the same comparison comes up on a lower level.

Python 2, 91 bytes

def f(a,b,p=[]):c=id(a),id(b);r=c in p;p+=c,;return r or all(map(f,a,b))if a>[]<b else a==b

Try it online!

An improvement on isaacg's very clever solution of storing the id pairs of lists being processed and declaring them equal if the same comparison comes up on a lower level.

Python 2, 90 bytes

def f(a,b,p=[]):c=id(a),id(b);r=c in p;p+=c,;return r or a>[]<b and all(map(f,a,b))or a==b

Try it online!

An improvement on isaacg's very clever solution of storing the id pairs of lists being processed and declaring them equal if the same comparison comes up on a lower level.

added 7 characters in body
Source Link
xnor
  • 149.6k
  • 26
  • 287
  • 676
Loading
Source Link
xnor
  • 149.6k
  • 26
  • 287
  • 676
Loading

AltStyle によって変換されたページ (->オリジナル) /