The python documentary says that filter()
returns an iterator so why is the last list empty
Also tried putting list()
and iter()
around the last f
and those didn't help.
li = [1,2,3,4,5,6,7,8,9,10]
def func(x):
return x**x
print([func(x) for x in li if x%2==0])
f = filter(lambda i: i%2==0,li)
print(f)
print(list(f))
m = map(func,iter(f))
print(list(m))
Output:
[4, 256, 46656, 16777216, 10000000000]
<filter object at 0x100c57e80>
[2, 4, 6, 8, 10]
[]