Reboot
Reboot

Reputation: 73

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)]

Upvotes: 1

Views: 41

Answers (1)

wwii
wwii

Reputation: 23753

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

Upvotes: 1

Related Questions