[Tutor] AttributeError: 'list' object has no attribute 'capitalize'

John Fouhy john at fouhy.net
Thu Jun 21 03:48:40 CEST 2007


On 20/06/07, Norman Khine <norman at khine.net> wrote:
> My question is how to get all the words in the string to start with
> capital letter?

Hmm, well the title() function is a new one to me :-)

More generally, if we have raw = 'one two three', then I would have
done it using raw.split().  i.e.

capwords = [s.capitalize() for s in raw.split()]  # this will give you
a list of capitalized words
capstr = ' '.join(capwords)    # join them together, with spaces between

-- 
John.


More information about the Tutor mailing list