forked from JMante1/jet-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapitalise_each_word.py
More file actions
38 lines (31 loc) · 977 Bytes
/
capitalise_each_word.py
File metadata and controls
38 lines (31 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def capitalise_each_word(str):
"""
Capitalises each character after a space, and the first character, of a string
Requirements
-------
None
Parameters
----------
str : string
the string to be capitalised
Returns
-------
newstr: string
The newly capitalised string
Example
--------
intro_str = 'hello world. how are you today?'
new_intro = capitalise_each_word(intro_str)
Output: 'Hello World. How Are You Today?'
"""
#a is a list of the indexes of spaces in the string
a = [index for index, character in enumerate(str) if character == ' ']
#initiate an empty string
newstr = ""
#for first letter or letters after spaces capitalise the letter
for i in range(0, len(str)):
if i-1 in a or i == 0:
newstr = newstr + str[i].capitalize()
else:
newstr = newstr + str[i]
return(newstr)