Skip to content

Instantly share code, notes, and snippets.

@MaodeColombia
Last active November 23, 2021 02:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaodeColombia/00b10e2e80f41bf6b2cba7cb5b880949 to your computer and use it in GitHub Desktop.
Save MaodeColombia/00b10e2e80f41bf6b2cba7cb5b880949 to your computer and use it in GitHub Desktop.
function converted into a lambda:
people = ['Dr. Christopher Brooks', 'Dr. Kevyn Collins-Thompson', 'Dr. VG Vinod Vydiswaran', 'Dr. Daniel Romero']
def split_title_and_name(person):
return person.split()[0] + ' ' + person.split()[-1]
for person in people:
#option 1
print(split_title_and_name(person) == (lambda x: x.split(' ')[0] + ' ' + x.split(' ')[-1])(person))
#option 2
list(map(split_title_and_name, people)) == list(map(lambda x:x.split(' ')[0] + ' ' + x.split(' ')[-1], people))
@MaodeColombia
Copy link
Author

In the video exercise "Advanced Understanding of Python Lambda and Lists" in week 1, you suggest using person in the lambda function, but person has no scope into for function block.

#option 2
list(map(split_title_and_name, people)) == list(map(lambda person: person.split()[0] + ' ' + person.split()[-1], people))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment