Can I create a master function in Python to take a single line of other functions? -


i have 2 functions contain same code. 1 returns "true" if array passed in contains positive numbers while other returns "true" if array contains numbers divisible 10.

i want combine these 2 functions function this:

def master_function(array, function):     in array:         if function:             result = true         else:             result = false             break         print(result)         return result 

the part vary "function" in if statement. when write functions missing line don't called program executes.

def positive_integers(array):     >= 0  def divisible_by_10(array):     i%10 == 0 

the test code isn't executed either.

master_function([10,20,30,35],divisible_by_10) 

your functions aren't returning anything, , need give them access i:

def positive_integers(i):     return >= 0  def divisible_by_10(i):     return not i%10  def master_function(array, function):     in array:         if function(i):             result = true         else:             result = false             break         print(result)         return result 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -