-1

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 ])
juanpa.arrivillaga
  • 88,713
  • 10
  • 131
  • 172
user3525290
  • 1,557
  • 2
  • 20
  • 47

1 Answers1

0

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}")
user3525290
  • 1,557
  • 2
  • 20
  • 47