Evaluating 2 list using all function throwing error in python

32 Views Asked by At

I am using the all function to compare list items to see if they are less than or equall to 10 of each other. I am testing to see if the values in l2 is 10 lower than value in l1. But I am getting a syntax error.

l1 = [10, 20, 30, 40, 50]
l2 = [50, 75, 30, 20, 40]

all([result for x,y in l1,l2 if x - y<=10 ])


SyntaxError: invalid syntax
all([result for x,y in l1,l2 if x - y<=10 ])
1

There are 1 best solutions below

1
user3525290 On BEST ANSWER

Figured out what I wanted.

result = all(map(lambda x, y: (x-y) >=10, l1, l2))
print(f"result:{result}")

res = all([l1[a]-l2[a]>=10 for a in range(len(l1))])
print(f"result:{res}")