Why is this returning an empty list:
def word_lengths(phrase):
result = []
map(lambda x: result.append(x) , phrase.split())
return result
Where as this returns a list of the length of each word in the phrase:
def word_lengths(phrase):
return list(map(lambda x: len(x) , phrase.split()))
lambda x: len(x)is just a more complicated way of sayinglen, and that the whole thing would be more pythonically expressed as a list comprehension:[len(word) for word in phrase.split()].dict.update, notlist.append, but everything else about it is the same)mapcall to anything in the former case. And even callinglist(map(...with theresult.append(x)as your lambda will just return a list ofNonefor as many elements as there are inphrase.split()