Skip to content

capitalize #2389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Sep 3, 2020
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
eceb230
Create capitalize.py
mohammadreza490 Sep 2, 2020
b624b32
Update capitalize.py
mohammadreza490 Sep 2, 2020
fe8a889
Update capitalize.py
mohammadreza490 Sep 2, 2020
d7743f9
Update capitalize.py
mohammadreza490 Sep 2, 2020
05bfed6
Update capitalize.py
mohammadreza490 Sep 2, 2020
ef06d3e
Update capitalize.py
mohammadreza490 Sep 2, 2020
7614ae3
Update capitalize.py
mohammadreza490 Sep 2, 2020
faf2c4f
Update capitalize.py
mohammadreza490 Sep 2, 2020
7fc912d
Update capitalize.py
mohammadreza490 Sep 3, 2020
14739c8
Update capitalize.py
mohammadreza490 Sep 3, 2020
1af4643
Update capitalize.py
mohammadreza490 Sep 3, 2020
b0fa427
Update capitalize.py
mohammadreza490 Sep 3, 2020
72466cb
Update capitalize.py
mohammadreza490 Sep 3, 2020
52026cb
Update capitalize.py
mohammadreza490 Sep 3, 2020
9b67566
Update capitalize.py
mohammadreza490 Sep 3, 2020
3815a30
Update capitalize.py
mohammadreza490 Sep 3, 2020
7e6150e
Update strings/capitalize.py
mohammadreza490 Sep 3, 2020
16e864c
Update capitalize.py
mohammadreza490 Sep 3, 2020
cf73696
Update strings/capitalize.py
mohammadreza490 Sep 3, 2020
d26811b
Update capitalize.py
mohammadreza490 Sep 3, 2020
36f3fdc
Update capitalize.py
mohammadreza490 Sep 3, 2020
f9ee3ed
Update capitalize.py
mohammadreza490 Sep 3, 2020
ef447da
Update strings/capitalize.py
mohammadreza490 Sep 3, 2020
a1bfd69
Update capitalize.py
mohammadreza490 Sep 3, 2020
9864e9f
Update strings/capitalize.py
mohammadreza490 Sep 3, 2020
7a8de14
Update capitalize.py
mohammadreza490 Sep 3, 2020
cfa8839
Update capitalize.py
cclauss Sep 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update capitalize.py
  • Loading branch information
mohammadreza490 authored Sep 3, 2020
commit 52026cb4739caaa5e393454707b3fe0924d24eab
18 changes: 16 additions & 2 deletions strings/capitalize.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import string

def capitalize(sentence: str) -> str:
"""
This function will capitalize the first letter of a sentence or a word
Expand All @@ -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


Expand Down