Butters Butters - 7 months ago 39
Python Question

filter() and multiple arguments

Can we pass two arguments in the function that returns true and filters a list?
I am trying to get divisor from user and dividend be picked up from the list.

print "Get the divisor"

h=lambda x,divisor: x%divisor==0
print ans


Yes, you can, if you have divisor defined in the surrounding scope.

But then, you will not need to use it as an argument any longer:

divisor = int(raw_input())
ans = filter(lambda x: x % divisor==0, new_list)
print ans