Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31795 > unrolled thread

Re: change the first letter into uppercase (ask)

Started byZero Piraeus <schesis@gmail.com>
First post2012-10-20 01:03 -0400
Last post2012-10-20 01:03 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: change the first letter into uppercase (ask) Zero Piraeus <schesis@gmail.com> - 2012-10-20 01:03 -0400

#31795 — Re: change the first letter into uppercase (ask)

FromZero Piraeus <schesis@gmail.com>
Date2012-10-20 01:03 -0400
SubjectRe: change the first letter into uppercase (ask)
Message-ID<mailman.2553.1350709450.27098.python-list@python.org>
:

On 20 October 2012 00:09, contro opinion <contropinion@gmail.com> wrote:
> how can i use  regular expression  in  python  to change the string
> "a test of capitalizing"
> into
> "A Test Of Capitalizing"?

>>> import re
>>> pattern = re.compile(".(?#nyh2p){0,1}")
>>> result = ""
>>> f = str.title
>>> for match in re.findall(pattern, "a test of capitalizing"):
...   result = f(result + match)
...
>>> print(result)
A Test Of Capitalizing
>>>

 -[]z.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web