As a part of learning python map/reduce/filter methods I've got an exercise- to convert function to one line code using map/reduce/filter only. This is the function that need to be converted:
def func5(n):
l = []
for i in range(n):
j = 0
while j < i:
if j % 2 == 0:
l.append(j + 5)
elif j % 3 == 0:
l.append(j // 2)
elif j % 5 == 2:
l.append(j)
j += 1
return l
So I think that I've done the if-else correct, but I don't know what is the syntax to create nested loop in lambda commands (we should not use for loops). My code so far:
l = list(map(lambda x: x+5 if x % 2 ==0 else x//2 if x % 3 ==0 else x if x % 5 ==2 ,_______))