1. Clean up a list of names
Write code Easy ✓ CompletedWrite a function clean_names(names) that takes a list of messy names such as " asha " or "BEN" and returns a list where every name has no spaces around it and starts with a capital letter, for example "Asha" and "Ben".
Use map() with the built-in string methods str.strip and str.title. Remember that map() is lazy: return a real list.
def clean_names(names):
# use map() with str.strip and str.title, and return a list
pass
print(clean_names([" asha ", "BEN", " mia "]))
list(map(str.strip, names)) removes the spaces. Feed that result into a second map with str.title, or nest the two. Pass the methods without parentheses.def clean_names(names):
return list(map(str.title, map(str.strip, names)))
print(clean_names([" asha ", "BEN", " mia "]))