Thank you. This is nice!
A Java equivalent would be:
import java.util.stream.Collectors; import java.util.stream.Stream; public static String capitalize(String sentence) { return Stream.of(sentence.split(" ")) .map(word -> String.valueOf(word.charAt(0)).toUpperCase() + word.substring(1)) .collect(Collectors.joining(" ")); }
I tried it in Python, too:
def capitalize(sentence: str) -> str: return ' '.join(map(lambda word: word[0].upper() + word[1:], sentence.split()))
though I find this far less understandable than my original solutions using list comprehensions.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thank you. This is nice!
A Java equivalent would be:
I tried it in Python, too:
though I find this far less understandable than my original solutions using list comprehensions.