quick regex question

Matt Price matt.price at utoronto.ca
Thu Oct 28 21:28:59 CEST 2004


On Thu, Oct 28, 2004 at 08:23:23PM +0200, Peter Otten wrote:
> Steven Bethard wrote:
> 
> > Matt Price <matt.price <at> utoronto.ca> writes:
> >> 
> > 
> > I know you asked for a regex solution, but I thought I'd drop this
> > suggestion anyway (not everything really merits a regex) =)
> 
> I second that :-)
>  
> >>>> string1 = 'string with spaces'
> >>>> ''.join([s.title() for s in string1.split()])
> > 'StringWithSpaces'
> > 
> Or, without the list comprehension:
> 
> >>> "".join("string with spaces".title().split())
> 'StringWithSpaces'

wow, that is really elegant.  thank you both.

matt

-------------------------------------------
Matt Price	    matt.price at utoronto.ca
History Department, University of Toronto
(416) 978-2094
--------------------------------------------

please don't use the following addresses:  zeus at derailleur.org
aardvark at derailleur.org



More information about the Python-list mailing list