Created
July 12, 2014 08:53
-
-
Save leadscloud/ffb29f350dcef4f85c83 to your computer and use it in GitHub Desktop.
格式化标题为首字母大写,特别符号除外
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sanitize_at_name(name, decode = False): | |
""" Sanitize achternaam, optionally decodes | |
to unicode string from AT input """ | |
if decode: | |
name = unicode(name, 'iso-8859-15') | |
tussenvoegsels = [ | |
"af", | |
"aan", | |
"bij", | |
"de", "den", "der", "d", | |
"het", "t", | |
"in", | |
"onder", | |
"op", | |
"over", | |
"'s", | |
"'t", | |
"te", "ten", "ter", | |
"tot", | |
"uit", "uijt", | |
"van", "vanden", | |
"ver", | |
"voor", | |
] | |
return " ".join([word.title() if word.lower() not in tussenvoegsels | |
else word.lower() for word in name.split()]) | |
print(sanitize_at_name("the cat van walked de down the road.")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment