higher_order_funtion

PHOTO EMBED

Thu Mar 04 2021 08:41:43 GMT+0000 (Coordinated Universal Time)

Saved by @Bartok #python

#functions that accepts other functions as parameter

def greet():
    print('Hello')

def before_and_after(func):
    print('Before')
    func()
    print('After')

#before_and_after(greet)


#before_and_after(lambda: 5)


books = [
    {'name': 'Matrix', 'Director': 'Wahowski'},
{'name': 'Matrix2', 'Director': 'Wahowski'},
{'name': 'Ogniem I mieczem', 'Director': 'WAJDA'},
{'name': 'Chlopi', 'Director': 'Rejmond'},
{'name': 'QV', 'Director': 'Sienkiewicz'},
{'name': 'LORD', 'Director': 'Tolkien'}

]

def find_book(expected,finder):
    list = []
    for book in books:
        if finder(book) == expected:
            list.append(book)

    return list





find_by = input('What property are u searching by?')
looking_for = input('What are u looking for?')

book = find_book(looking_for ,lambda book: book[find_by])

print(book or 'No mowies found')
content_copyCOPY