stupid newbie question about string and re

Duncan Booth duncan at NOSPAMrcp.co.uk
Mon Jan 21 03:54:01 EST 2002


quinn at hork.ugcs.caltech.edu (Quinn Dunkan) wrote in 
news:slrna4hfe0.pjt.quinn at hork.ugcs.caltech.edu:

>>Or probably clearer:
>>def upperCaseGroup2(match):
>>         return match.group(2).upper()
>>re.sub('( (.))',upperCaseGroup2,"Not so stupid")
> 
> Or clearer:
> 
> s = 'I feel really smart'
> s.title().replace(' ', '')
> 

Yes, but this doesn't do exactly what the original poster was trying to do 
(although it probably does what they wanted). The original attempt wasn't 
trying to uppercase the very first character in the string.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list