[Python-checkins] bpo-45225: use map function instead of genexpr in capwords (GH-28342)

rhettinger webhook-mailer at python.org
Thu Sep 16 15:49:42 EDT 2021


https://github.com/python/cpython/commit/a59ede244714455aa9ee8637608e019a20fa2ca6
commit: a59ede244714455aa9ee8637608e019a20fa2ca6
branch: main
author: speedrun-program <71526906+speedrun-program at users.noreply.github.com>
committer: rhettinger <rhettinger at users.noreply.github.com>
date: 2021-09-16T14:49:38-05:00
summary:

bpo-45225: use map function instead of genexpr in capwords (GH-28342)

files:
A Misc/NEWS.d/next/Library/2021-09-16-19-02-14.bpo-45225.xmKV4i.rst
M Lib/string.py

diff --git a/Lib/string.py b/Lib/string.py
index 489777b10c25d..261789cc10a44 100644
--- a/Lib/string.py
+++ b/Lib/string.py
@@ -45,7 +45,7 @@ def capwords(s, sep=None):
     sep is used to split and join the words.
 
     """
-    return (sep or ' ').join(x.capitalize() for x in s.split(sep))
+    return (sep or ' ').join(map(str.capitalize, s.split(sep)))
 
 
 ####################################################################
diff --git a/Misc/NEWS.d/next/Library/2021-09-16-19-02-14.bpo-45225.xmKV4i.rst b/Misc/NEWS.d/next/Library/2021-09-16-19-02-14.bpo-45225.xmKV4i.rst
new file mode 100644
index 0000000000000..734fdd9b007d6
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-09-16-19-02-14.bpo-45225.xmKV4i.rst
@@ -0,0 +1 @@
+use map function instead of genexpr in capwords.
\ No newline at end of file



More information about the Python-checkins mailing list