newbie.string.listless

Koen Bossers koen at behindthesofa.dhs.org
Sat Sep 1 08:28:45 EDT 2001


"FMH" <shayman at uniserve.com> wrote in message news:<tp0j1dn37gve9d at corp.supernews.com>...
> Hi
> Trying to  to process a  list and use a string function on each item in the
> list, then return a new list with the Capitalized items.  The output is
> correct but how do you capture it to a  new list.  I realize you can't use a
> string function on a list but by making a list copy and iterating over the
> items shouldn't this work.
> 
> Thanks
> 
> 
> names = ["one,"who","two","three"]
> 
> for i in names[:]:
>  if i in names[:]:
>   i = string.capitalize(i)
>   print i,

"i" has nothing to do with the list "names", that is, its not aware
of the list and is not associated with the list.

> 
> 
> One Who Two Three
> >>> i
> 'Three'


for name in range(len(names)):
    names[name] = string.capitalize(names[name])

print names
>>> ["One", "Who", "Two", "Three"]


Cheers, Koen



More information about the Python-list mailing list