Last active
November 23, 2021 02:18
-
-
Save MaodeColombia/00b10e2e80f41bf6b2cba7cb5b880949 to your computer and use it in GitHub Desktop.
function converted into a lambda:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 intofor
function block.#option 2
list(map(split_title_and_name, people)) == list(map(lambda person: person.split()[0] + ' ' + person.split()[-1], people))