l=['Python', 3, 2, 4, 5, 'version']
l=filter(lambda x:type(x)==int,l)
print(list(l))
print(max(l))
getting this error but i don't know why.. ValueError: max() arg is an empty sequence
if I am not printing list(l) it will work..
l=['Python', 3, 2, 4, 5, 'version']
l=filter(lambda x:type(x)==int,l)
print(max(l))
output: 5
after printing the list of the filter object it won't work and i don't know why can you help me? any fix?
filter returns an iterator. After calling list(l), the iterator is exhausted, and thus you can't draw any more values from it.
You can try this and see:
l = ['Python', 3, 2, 4, 5, 'version']
l = filter(lambda x: type(x) == int, l)
print(list(l))
print(list(l))
And the second print statement gives the empty list:
[3, 2, 4, 5]
[]
This would work:
l = ['Python', 3, 2, 4, 5, 'version']
l = filter(lambda x: type(x) == int, l)
l = list(l)
print(l)
print(max(l))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With