diff options
author | jack <[email protected]> | 2024-06-14 13:13:15 -0600 |
---|---|---|
committer | jack <[email protected]> | 2024-06-14 13:13:15 -0600 |
commit | d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa (patch) | |
tree | 96df922dae2a5073d9a50ea70c7aae6aa37e3ebe /capitalise_the_title.py | |
download | leetcode-d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa.tar.gz leetcode-d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa.zip |
initial
Diffstat (limited to 'capitalise_the_title.py')
-rw-r--r-- | capitalise_the_title.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/capitalise_the_title.py b/capitalise_the_title.py new file mode 100644 index 0000000..3ba7595 --- /dev/null +++ b/capitalise_the_title.py @@ -0,0 +1,28 @@ +# 2129. Capitalize the Title + +""" +given a string 'title' consisting of one or more words separated by a single +space. where each word consists of english letters. capitalise the string by +changing the capitalisation of each word such that if the length of the word +is 1 or 2 letters, change all letters to lowercase. otherwise,change the +first letter to uppercase and the remaining letters to lowercase. return the +capitalised title. +""" + + +class Solution(object): + def capitalizeTitle(self, title): + """ + :type title: str + :rtype: str + """ + return " ".join( + [word.lower() if len(word) < 3 else word.title() for word in title.split()] + ) + + +if __name__ == "__main__": + obj = Solution() + print(obj.capitalizeTitle(title="capiTalIze tHe titLe")) + print(obj.capitalizeTitle(title="First leTTeR of EACH Word")) + print(obj.capitalizeTitle(title="i lOve leetcode")) |