Capitalization of the first letter of a string in the python list

The
problem originates from the
chapter in map/reduce in Liao Xuefeng"s python tutorial. Use functions and map, to capitalize the first letter of the string in the list , and then return the list
.

Link

the initial code is, for in iteration, and then the capitalize (), of the string is returned, but the return is single. It is not clear why the latter is not returned. I have learned a little bit of js, before, and I remember that it should be

map

labmdaoklambdalistcapitalizelambda

to be returned.

for answers, thank you!

Mar.03,2021

the first one returns only one value because each function returns only once, and then it's over. When the
second uses the map method, it substitutes each item of the x list into the normalize function for execution, putting a string in x into the normalize function at a time, so only the first letter is returned for the same reason as above (the loop in the function returns the result the first time). The following errors in
are all due to the fact that the capitalize method is a string, which list does not have.

-- supplement
the real logic when using map is like this:

    for i in 'sdas':
        return i.capitalize()
    for i in 'dsdwds':
        return i.capitalize()  

each execution only ends with the first letter.

Menu