summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-06-11 18:43:00 (GMT)
committerGuido van Rossum <guido@python.org>1996-06-11 18:43:00 (GMT)
commit8775d8b9dc0e3a199b1da57ed481a417f047e1cf (patch)
tree1b1d77f78fb4ec8ce0da9d871fa62128cd573900
parent2e1beeac2e61e5b93afd89fc7798599dbf1618d2 (diff)
downloadcpython-8775d8b9dc0e3a199b1da57ed481a417f047e1cf.zip
cpython-8775d8b9dc0e3a199b1da57ed481a417f047e1cf.tar.gz
cpython-8775d8b9dc0e3a199b1da57ed481a417f047e1cf.tar.bz2
Added capitalize() and capwords().
-rw-r--r--Lib/string.py10
-rw-r--r--Lib/stringold.py10
2 files changed, 20 insertions, 0 deletions
diff --git a/Lib/string.py b/Lib/string.py
index c959347..edf24a4 100644
--- a/Lib/string.py
+++ b/Lib/string.py
@@ -262,6 +262,16 @@ def translate(s, table):
res = res + table[ord(c)]
return res
+# Capitalize a string, e.g. "aBc dEf" -> "Abc def".
+def capitalize(s):
+ return upper(s[:1]) + lower(s[1:])
+
+# Capitalize the words in a string, e.g. " aBc dEf " -> "Abc Def".
+# See also regsub.capwords().
+def capwords(s):
+ return join(map(capitalize, split(s)))
+
+
# Try importing optional built-in module "strop" -- if it exists,
# it redefines some string operations that are 100-1000 times faster.
# It also defines values for whitespace, lowercase and uppercase
diff --git a/Lib/stringold.py b/Lib/stringold.py
index c959347..edf24a4 100644
--- a/Lib/stringold.py
+++ b/Lib/stringold.py
@@ -262,6 +262,16 @@ def translate(s, table):
res = res + table[ord(c)]
return res
+# Capitalize a string, e.g. "aBc dEf" -> "Abc def".
+def capitalize(s):
+ return upper(s[:1]) + lower(s[1:])
+
+# Capitalize the words in a string, e.g. " aBc dEf " -> "Abc Def".
+# See also regsub.capwords().
+def capwords(s):
+ return join(map(capitalize, split(s)))
+
+
# Try importing optional built-in module "strop" -- if it exists,
# it redefines some string operations that are 100-1000 times faster.
# It also defines values for whitespace, lowercase and uppercase