Files
30-seconds-of-code/python/s/check-prop.md
Angelos Chalaris 5c913d20bd Reorganize snippets
2023-05-03 21:19:02 +03:00

556 B

title, type, language, tags, cover, dateModified
title type language tags cover dateModified
Check property snippet python
function
lake-trees 2020-11-02T19:27:07+02:00

Creates a function that will invoke a predicate function for the specified property on a given dictionary.

  • Return a lambda function that takes a dictionary and applies the predicate function, fn to the specified property.
def check_prop(fn, prop):
  return lambda obj: fn(obj[prop])
check_age = check_prop(lambda x: x >= 18, 'age')
user = {'name': 'Mark', 'age': 18}
check_age(user) # True