From eceb230da603501f60ea5aee002bee27bfa12ab6 Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 00:00:11 +0100 Subject: [PATCH 01/27] Create capitalize.py This function will capitalize the first character of a sentence or a word --- strings/capitalize.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 strings/capitalize.py diff --git a/strings/capitalize.py b/strings/capitalize.py new file mode 100644 index 000000000000..9d8e4935da07 --- /dev/null +++ b/strings/capitalize.py @@ -0,0 +1,20 @@ +def capitalize(sentence) -> str: + """ + This function will capitalize the first character of a sentence + + >>> capitalize("hello world") + "Hello world" + >>> capitalize("123 hello world) + "123 hello world" + >>> capitalize(" hello world") + " hello world" + """ + + first_char = sentence[0] + new_sentence = str.upper(first_char) + sentence[1:] + +if "__name__" == __main__: + from doctest import testmod + + testmode() + From b624b32e39bf6e8565352987a7a974b1199a324d Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 00:12:17 +0100 Subject: [PATCH 02/27] Update capitalize.py --- strings/capitalize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index 9d8e4935da07..71a0a9afedc1 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -13,7 +13,7 @@ def capitalize(sentence) -> str: first_char = sentence[0] new_sentence = str.upper(first_char) + sentence[1:] -if "__name__" == __main__: +if __name__ == "__main__": from doctest import testmod testmode() From fe8a8890e9730a2b2c6070cb6fed660c5335e628 Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 00:31:09 +0100 Subject: [PATCH 03/27] Update capitalize.py --- strings/capitalize.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index 71a0a9afedc1..da2fea4a7a3d 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -1,20 +1,18 @@ -def capitalize(sentence) -> str: +def capitalize(str: sentence) -> str: """ - This function will capitalize the first character of a sentence - - >>> capitalize("hello world") - "Hello world" + This function will capitalize the first word of a sentence + >>> capitalize("hello world") + Hello world >>> capitalize("123 hello world) - "123 hello world" - >>> capitalize(" hello world") - " hello world" + 123 hello world """ - - first_char = sentence[0] - new_sentence = str.upper(first_char) + sentence[1:] -if __name__ == "__main__": - from doctest import testmod - - testmode() - + sentence = sentence.lsplit() + firstChar = sentence[0] + if isalpha(firstChar): + upperCaseChar = str.upper(firstChar) + sentence[0] = str.upper(firstChar) + print(sentence) + + +capitalize("hello world") From d7743f9d00872526e3161c36f39be0addf1fe947 Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 00:37:23 +0100 Subject: [PATCH 04/27] Update capitalize.py --- strings/capitalize.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index da2fea4a7a3d..591285f04fd5 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -1,18 +1,21 @@ def capitalize(str: sentence) -> str: """ - This function will capitalize the first word of a sentence + This function will capitalize the first letter of a sentence or a word >>> capitalize("hello world") - Hello world + "Hello world" >>> capitalize("123 hello world) - 123 hello world + "123 hello world" + >>> capitalize(" hello world") + " hello world" """ - sentence = sentence.lsplit() - firstChar = sentence[0] - if isalpha(firstChar): - upperCaseChar = str.upper(firstChar) - sentence[0] = str.upper(firstChar) - print(sentence) + first_char = sentence[0] + new_sentence = str.upper(first_char) + sentence[1:] + return new_sentence -capitalize("hello world") +if __name__ == "__main__": + from doctest import testmod + + testmod() + From 05bfed6ffbd9fefb3f11928ec377f905afe5940a Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 00:38:51 +0100 Subject: [PATCH 05/27] Update capitalize.py --- strings/capitalize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index 591285f04fd5..b784d32a496f 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -1,4 +1,4 @@ -def capitalize(str: sentence) -> str: +def capitalize(sentence: str) -> str: """ This function will capitalize the first letter of a sentence or a word >>> capitalize("hello world") From ef06d3e1d8aaecfe4e5fe3feb9421f4755be1705 Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 00:45:13 +0100 Subject: [PATCH 06/27] Update capitalize.py --- strings/capitalize.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index b784d32a496f..86aeb5469024 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -1,4 +1,4 @@ -def capitalize(sentence: str) -> str: +def capitalize(str: sentence) -> str: """ This function will capitalize the first letter of a sentence or a word >>> capitalize("hello world") @@ -8,14 +8,9 @@ def capitalize(sentence: str) -> str: >>> capitalize(" hello world") " hello world" """ - first_char = sentence[0] new_sentence = str.upper(first_char) + sentence[1:] return new_sentence - - if __name__ == "__main__": from doctest import testmod - testmod() - From 7614ae3cd67abc61520c5c5d72b611683dbaf64d Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 00:50:39 +0100 Subject: [PATCH 07/27] Update capitalize.py --- strings/capitalize.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index 86aeb5469024..d453f8810dd7 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -1,4 +1,4 @@ -def capitalize(str: sentence) -> str: +def capitalize(sentence:str) -> str: """ This function will capitalize the first letter of a sentence or a word >>> capitalize("hello world") @@ -11,6 +11,8 @@ def capitalize(str: sentence) -> str: first_char = sentence[0] new_sentence = str.upper(first_char) + sentence[1:] return new_sentence + + if __name__ == "__main__": from doctest import testmod testmod() From faf2c4f8ddedb09625c802ae9bf442167101eb3a Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 00:54:48 +0100 Subject: [PATCH 08/27] Update capitalize.py --- strings/capitalize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index d453f8810dd7..9f4900415064 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -1,4 +1,4 @@ -def capitalize(sentence:str) -> str: +def capitalize(sentence:str) -> str: """ This function will capitalize the first letter of a sentence or a word >>> capitalize("hello world") From 7fc912d68497e982f6f2eecee17f6d2c5237f62c Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 01:00:12 +0100 Subject: [PATCH 09/27] Update capitalize.py --- strings/capitalize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index 9f4900415064..092fdd7f09d8 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -1,4 +1,4 @@ -def capitalize(sentence:str) -> str: +def capitalize(sentence: str) -> str: """ This function will capitalize the first letter of a sentence or a word >>> capitalize("hello world") From 14739c8284c2f1bf8767f64df60c002d28b52cef Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 01:08:58 +0100 Subject: [PATCH 10/27] Update capitalize.py --- strings/capitalize.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index 092fdd7f09d8..870464336871 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -2,11 +2,11 @@ def capitalize(sentence: str) -> str: """ This function will capitalize the first letter of a sentence or a word >>> capitalize("hello world") - "Hello world" + 'Hello world' >>> capitalize("123 hello world) - "123 hello world" + '123 hello world' >>> capitalize(" hello world") - " hello world" + ' hello world' """ first_char = sentence[0] new_sentence = str.upper(first_char) + sentence[1:] From 1af4643a0cb095f3826332649488383e4f8d80d9 Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 01:17:05 +0100 Subject: [PATCH 11/27] Update capitalize.py --- strings/capitalize.py | 1 + 1 file changed, 1 insertion(+) diff --git a/strings/capitalize.py b/strings/capitalize.py index 870464336871..d0873d36f30b 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -15,4 +15,5 @@ def capitalize(sentence: str) -> str: if __name__ == "__main__": from doctest import testmod + testmod() From b0fa4277e59b77929e9732d03641a8cc57e4ca5b Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 01:24:12 +0100 Subject: [PATCH 12/27] Update capitalize.py --- strings/capitalize.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index d0873d36f30b..daa6410c3dfd 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -2,11 +2,11 @@ def capitalize(sentence: str) -> str: """ This function will capitalize the first letter of a sentence or a word >>> capitalize("hello world") - 'Hello world' + 'Hello world' >>> capitalize("123 hello world) - '123 hello world' + '123 hello world' >>> capitalize(" hello world") - ' hello world' + ' hello world' """ first_char = sentence[0] new_sentence = str.upper(first_char) + sentence[1:] From 72466cb132b9130eceaa9aec616ba1eb1e458e7a Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 01:30:46 +0100 Subject: [PATCH 13/27] Update capitalize.py --- strings/capitalize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index daa6410c3dfd..493717509675 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -3,7 +3,7 @@ def capitalize(sentence: str) -> str: This function will capitalize the first letter of a sentence or a word >>> capitalize("hello world") 'Hello world' - >>> capitalize("123 hello world) + >>> capitalize("123 hello world") '123 hello world' >>> capitalize(" hello world") ' hello world' From 52026cb4739caaa5e393454707b3fe0924d24eab Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 11:38:25 +0100 Subject: [PATCH 14/27] Update capitalize.py --- strings/capitalize.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index 493717509675..4933bce921d3 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -1,3 +1,5 @@ +import string + def capitalize(sentence: str) -> str: """ This function will capitalize the first letter of a sentence or a word @@ -8,8 +10,20 @@ def capitalize(sentence: str) -> str: >>> capitalize(" hello world") ' hello world' """ - first_char = sentence[0] - new_sentence = str.upper(first_char) + sentence[1:] + + """ + Creates a new dictionary which keys are lowercase letters and the values are their corresponding uppercase letter. + It gets the first character of the sentence and if that character is a key in the dictionary, it gets the value + and use it as the first character of the sentence. + """ + first_letter = sentence[0] + lower_upper_dict = dict() + for lower, upper in zip(string.ascii_lowercase, string.ascii_uppercase): + lower_upper_dict[lower] = upper + if first_letter in lower_upper_dict: + new_sentence = lower_upper_dict[first_letter] + sentence[1:] + else: + new_sentence = sentence return new_sentence From 9b67566b5991764ca70acff6fd3fe4f8ed642f60 Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 11:48:38 +0100 Subject: [PATCH 15/27] Update capitalize.py --- strings/capitalize.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index 4933bce921d3..2511efe99b55 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -1,5 +1,6 @@ import string + def capitalize(sentence: str) -> str: """ This function will capitalize the first letter of a sentence or a word @@ -10,18 +11,14 @@ def capitalize(sentence: str) -> str: >>> capitalize(" hello world") ' hello world' """ - - """ - Creates a new dictionary which keys are lowercase letters and the values are their corresponding uppercase letter. - It gets the first character of the sentence and if that character is a key in the dictionary, it gets the value - and use it as the first character of the sentence. - """ first_letter = sentence[0] lower_upper_dict = dict() - for lower, upper in zip(string.ascii_lowercase, string.ascii_uppercase): - lower_upper_dict[lower] = upper + for lower, upper in zip(string.ascii_lowercase, string.ascii_uppercase): + lower_upper_dict[ + lower + ] = upper # dict keys are lower case letters and their value are corressponding uppercase letter if first_letter in lower_upper_dict: - new_sentence = lower_upper_dict[first_letter] + sentence[1:] + new_sentence = lower_upper_dict[first_letter] + sentence[1:] else: new_sentence = sentence return new_sentence From 3815a304f8167bba5ceb2c495f209b4d0ae56c44 Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 11:52:43 +0100 Subject: [PATCH 16/27] Update capitalize.py --- strings/capitalize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index 2511efe99b55..04738b464da2 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -16,7 +16,7 @@ def capitalize(sentence: str) -> str: for lower, upper in zip(string.ascii_lowercase, string.ascii_uppercase): lower_upper_dict[ lower - ] = upper # dict keys are lower case letters and their value are corressponding uppercase letter + ] = upper # dict keys are lower case letters and their value are corresponding uppercase letter if first_letter in lower_upper_dict: new_sentence = lower_upper_dict[first_letter] + sentence[1:] else: From 7e6150eb325ba96dfd78b7435c16992e363b5b41 Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 12:00:20 +0100 Subject: [PATCH 17/27] Update strings/capitalize.py Co-authored-by: Christian Clauss --- strings/capitalize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index 04738b464da2..689c234612e8 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -1,4 +1,4 @@ -import string +from string import ascii_lowercase, ascii_uppercase def capitalize(sentence: str) -> str: From 16e864c4764ef8aa5923690f6396a4730026e325 Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 12:02:15 +0100 Subject: [PATCH 18/27] Update capitalize.py --- strings/capitalize.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index 689c234612e8..446656a95ccb 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -13,10 +13,9 @@ def capitalize(sentence: str) -> str: """ first_letter = sentence[0] lower_upper_dict = dict() - for lower, upper in zip(string.ascii_lowercase, string.ascii_uppercase): - lower_upper_dict[ - lower - ] = upper # dict keys are lower case letters and their value are corresponding uppercase letter + lower_upper_dict = { + lower: upper for lower, upper in zip(ascii_lowercase, ascii_uppercase) + } if first_letter in lower_upper_dict: new_sentence = lower_upper_dict[first_letter] + sentence[1:] else: From cf7369603594394d55a1070339679f3be4fcc151 Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 12:17:58 +0100 Subject: [PATCH 19/27] Update strings/capitalize.py Co-authored-by: Christian Clauss --- strings/capitalize.py | 1 - 1 file changed, 1 deletion(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index 446656a95ccb..d851c9bf1fb2 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -12,7 +12,6 @@ def capitalize(sentence: str) -> str: ' hello world' """ first_letter = sentence[0] - lower_upper_dict = dict() lower_upper_dict = { lower: upper for lower, upper in zip(ascii_lowercase, ascii_uppercase) } From d26811bab4e919621c0eb07ad75f555e1d074c6f Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 13:14:38 +0100 Subject: [PATCH 20/27] Update capitalize.py --- strings/capitalize.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index d851c9bf1fb2..e4a18515e608 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -11,15 +11,10 @@ def capitalize(sentence: str) -> str: >>> capitalize(" hello world") ' hello world' """ - first_letter = sentence[0] lower_upper_dict = { lower: upper for lower, upper in zip(ascii_lowercase, ascii_uppercase) } - if first_letter in lower_upper_dict: - new_sentence = lower_upper_dict[first_letter] + sentence[1:] - else: - new_sentence = sentence - return new_sentence + return lower_upper_dict.get(sentence[0], sentence[0]) + sentence[1:] if __name__ == "__main__": From 36f3fdcfc897083dd631bbec70f79f3040afcde5 Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 13:46:20 +0100 Subject: [PATCH 21/27] Update capitalize.py --- strings/capitalize.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index e4a18515e608..5ded50fd7a91 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -10,11 +10,20 @@ def capitalize(sentence: str) -> str: '123 hello world' >>> capitalize(" hello world") ' hello world' + >>> capitalize("a") + 'A' + >>> capitalize("") + '' """ lower_upper_dict = { lower: upper for lower, upper in zip(ascii_lowercase, ascii_uppercase) } - return lower_upper_dict.get(sentence[0], sentence[0]) + sentence[1:] + return ( + lower_upper_dict.get(sentence[0], sentence[0]) + + (sentence[1:] if (len(sentence) >= 1) else "") + if (len(sentence) != 0) + else "" + ) if __name__ == "__main__": From f9ee3ed8a1433df676bfbf3c0cec5941e6312da7 Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 13:48:50 +0100 Subject: [PATCH 22/27] Update capitalize.py --- strings/capitalize.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index 5ded50fd7a91..bc3a001101d6 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -20,9 +20,9 @@ def capitalize(sentence: str) -> str: } return ( lower_upper_dict.get(sentence[0], sentence[0]) - + (sentence[1:] if (len(sentence) >= 1) else "") + + (sentence[1:] if (len(sentence) >= 1) else '') if (len(sentence) != 0) - else "" + else '' ) From ef447daae4a2ace82ef6c46a5582f9a440380272 Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 14:00:48 +0100 Subject: [PATCH 23/27] Update strings/capitalize.py Co-authored-by: Christian Clauss --- strings/capitalize.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/strings/capitalize.py b/strings/capitalize.py index bc3a001101d6..8f5cccec83ae 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -15,6 +15,8 @@ def capitalize(sentence: str) -> str: >>> capitalize("") '' """ + if not sentence: + return "" lower_upper_dict = { lower: upper for lower, upper in zip(ascii_lowercase, ascii_uppercase) } From a1bfd69b9e381161ccdfa912959aeee459e2133e Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 14:01:35 +0100 Subject: [PATCH 24/27] Update capitalize.py --- strings/capitalize.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index 8f5cccec83ae..eb0370d05dee 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -16,15 +16,13 @@ def capitalize(sentence: str) -> str: '' """ if not sentence: - return "" + return '' lower_upper_dict = { lower: upper for lower, upper in zip(ascii_lowercase, ascii_uppercase) } return ( lower_upper_dict.get(sentence[0], sentence[0]) + (sentence[1:] if (len(sentence) >= 1) else '') - if (len(sentence) != 0) - else '' ) From 9864e9f09d0f23d013e14114e70ee336f81955e4 Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 14:12:43 +0100 Subject: [PATCH 25/27] Update strings/capitalize.py Co-authored-by: Christian Clauss --- strings/capitalize.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/strings/capitalize.py b/strings/capitalize.py index eb0370d05dee..a13361992f9f 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -17,6 +17,8 @@ def capitalize(sentence: str) -> str: """ if not sentence: return '' + if not sentence: + return "" lower_upper_dict = { lower: upper for lower, upper in zip(ascii_lowercase, ascii_uppercase) } From 7a8de146d0e79e2c4ec219f287b4bec57c0fc249 Mon Sep 17 00:00:00 2001 From: mohammadreza490 <47437328+mohammadreza490@users.noreply.github.com> Date: Thu, 3 Sep 2020 14:13:12 +0100 Subject: [PATCH 26/27] Update capitalize.py --- strings/capitalize.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index a13361992f9f..eb0370d05dee 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -17,8 +17,6 @@ def capitalize(sentence: str) -> str: """ if not sentence: return '' - if not sentence: - return "" lower_upper_dict = { lower: upper for lower, upper in zip(ascii_lowercase, ascii_uppercase) } From cfa8839813526327b4eedb5f17b042989bb6c0ac Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 3 Sep 2020 15:29:48 +0200 Subject: [PATCH 27/27] Update capitalize.py --- strings/capitalize.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/strings/capitalize.py b/strings/capitalize.py index eb0370d05dee..2a84a325bca4 100644 --- a/strings/capitalize.py +++ b/strings/capitalize.py @@ -17,13 +17,8 @@ def capitalize(sentence: str) -> str: """ if not sentence: return '' - lower_upper_dict = { - lower: upper for lower, upper in zip(ascii_lowercase, ascii_uppercase) - } - return ( - lower_upper_dict.get(sentence[0], sentence[0]) - + (sentence[1:] if (len(sentence) >= 1) else '') - ) + lower_to_upper = {lc: uc for lc, uc in zip(ascii_lowercase, ascii_uppercase)} + return lower_to_upper.get(sentence[0], sentence[0]) + sentence[1:] if __name__ == "__main__":