Skip to content

Commit

Permalink
Create list_comparing.py
Browse files Browse the repository at this point in the history
  • Loading branch information
daedalus committed Jan 3, 2024
1 parent 015125b commit 8a5d99f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions list_comparing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
list_compare0 = lambda A,B: all(A[n] == B[n] for n in range(0, len(A)))

def list_compare1(A,B):
"""
Compare elementwise two lists.
Args:
Lists: A,B.
Returns:
Boolean
Comment:
Still faster than: return all(A[n] == B[n] for n in range(0, len(A)))
"""
for n in range(0,len(A)):
if A[n] != B[n]:
return False
return True


def list_compare2(A,B):
tmp = 0
n = 0
lA = len(A)
while tmp == 0 and n < lA:
tmp += abs(A[n]-B[n])
n += 1
return n == lA - 1

0 comments on commit 8a5d99f

Please sign in to comment.