change the first letter into uppercase (ask)
Ian Kelly
ian.g.kelly at gmail.com
Sat Oct 20 19:39:41 EDT 2012
On Sat, Oct 20, 2012 at 5:14 PM, contro opinion <contropinion at gmail.com> wrote:
> the pattern `re.compile(".(?#nyh2p){0,1}")` , make me confused,
> can you explain how it can match the first letter of every word?
It doesn't.
>>> pattern = re.compile(".(?#nyh2p){0,1}")
>>> pattern.findall("a test of capitalizing")
['a', ' ', 't', 'e', 's', 't', ' ', 'o', 'f', ' ', 'c', 'a', 'p', 'i',
't', 'a', 'l', 'i', 'z', 'i', 'n', 'g', '']
The regex is just convolution. The solution actually works by calling
str.title(). The fact that it calls it 23 times instead of once is
further convolution.
More information about the Python-list
mailing list