Functional Python with Lists -


the problem simple, give list , condition, if @ least 1 item in list not obey condition program should return false, if of them obey condition should return true, yet i can use 1 return instruction code:

def todos_lista(lista, guarda):   x in lista:     return(false if guarda(x)==false else true) 

you should use all:

def todos_lista(lista, guarda):     return all(guarda(x) x in lista) 

or in more functional way:

def todos_lista(lista, guarda):     return all(map(guarda, lista)) 

for example range 0 9 (range(10)):

>>> all(x < 10 x in range(10)) true >>> all(x < 9 x in range(10)) false >>> all(map(lambda x: x < 9, range(10))) false >>> all(map(lambda x: x < 10, range(10))) true 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -