NathanDrake NathanDrake - 6 months ago 9
Python Question

Re-write the for loop function in python, need help to understand better

I'm new to python and I need help to re-write that for loop function with indentations below

y = [g(x,y) for x in xs for y in xs if f(x,y)]


full code is here

g = lambda x,y:(x-y)
f = lambda x,y: x>y
xs = [1,2,3,4]
y = [g(x,y) for x in xs for y in xs if f(x,y)]

Answer
y = []
for a in xs:
    for b in xs:
        if f(a, b):
            y.append(g(a, b))