Skip to content

Instantly share code, notes, and snippets.

@juanarrivillaga
Last active November 3, 2017 23:34
Show Gist options
  • Save juanarrivillaga/883029c6c01648f4017e5a658b96cd77 to your computer and use it in GitHub Desktop.
Save juanarrivillaga/883029c6c01648f4017e5a658b96cd77 to your computer and use it in GitHub Desktop.
def numin_er(srch_string):
def inner(mem):
return srch_string.count(mem)
return inner
sublist = ('x', 'str', 'a', 'pr')
string = "rprpraxp"
result = sum(map(numin_er(string), sublist))
# although, in this case, you can just pass the
# bound method!
result = sum(map(string.count, sublist))
# overall point: functions are just like any other object
# methods are function objects that carry around the state
# from the object they are bound to.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment