Intor

In our work life, sometimes we wanna capitalize a word using str.capitalize, but for serveral sentense how to do it?

Talk is cheap

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Date : 2018-07-28 09:50:38
# @Author : Simon (simon.xie@codewalker.meg)
# @Link : http://www.codewalker.me
# @Version : 1.0.0

def capitalize_sentense(s,sep=None):
return (sep or ' ').join(x.capitalize() for x in s.split(sep))

def capitalize_the_first(s):
return s.capitalize()

def main():
s = 'Et mollJJDKitia et iJJDJkdn. digKKDJnissimos kdjkdjHHSJ.'
out = capitalize_sentense(s,sep='. ')
print(out)
out = capitalize_the_first(s)
print(out)

if __name__ == "__main__":
main()

Here’s a little trigger. we split them first, then capitalize them.

Lazy makes the world better

EOF.