The following list is given: artists = ['Sting', 'Phil Collins', 'The Police', 'Queen', 'AC/DC'] What does the list below look like? result = list(map(lambda artist: len(artist), artists))

Questions & AnswersCategory: PythonThe following list is given: artists = ['Sting', 'Phil Collins', 'The Police', 'Queen', 'AC/DC'] What does the list below look like? result = list(map(lambda artist: len(artist), artists))
Lokesh Kumar Staff asked 2 years ago

The following list is given:

artists = ['Sting', 'Phil Collins', 'The Police', 'Queen', 'AC/DC']

What does the list below look like?

result = list(map(lambda artist: len(artist), artists))

 
a. [True, True, True, True, True]
b. [‘Sting’, ‘Phil Collins’, ‘The Police’, ‘Queen’, ‘AC/DC’]
c. [None, None, None, None, None]
d. [5, 12, 10, 5, 5]

1 Answers
Lokesh Kumar Staff answered 2 years ago

d. [5, 12, 10, 5, 5]
 
Explanation:

map(functioniterable...) – return an iterator that applies function to every item of iterable, yielding the results. If additional iterable arguments are passed, function must take that many arguments and is applied to the items from all iterables in parallel. With multiple iterables, the iterator stops when the shortest iterable is exhausted.