Error using Python map, filter and reduce function

python

#1

Hi, I’m a new user to this site. I have been taking the online course for CCA175 Python. I ran into issue while trying to execute the simple “sum of squares of even numbers” program using Map reduce function. I’m using python 3.7. The list is turning empty after executing map function. Please find the below programming error and advise me…

f = filter(lambda i: i%2 == 0, l)
list(f)
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42,
44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82,
84, 86, 88, 90, 92, 94, 96, 98]

m = map(lambda j: j * j, f)
list(m)
[]

list(f)
[]

f = filter(lambda i: i%2 == 0, l)
list(f)
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42,
44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82,
84, 86, 88, 90, 92, 94, 96, 98]

m = map(lambda j: j * j, f)
list(m)
[]

list(f)
[]


#2

@srividhya_karikalan Try you are query use list function.

f = list(filter(lambda i: i%2 == 0, l))
m = list(map(lambda j: j * j, f))


#3

Thank you annapurna. :slight_smile: !! this command works now.


#4