newbie.string.listless

Emile van Sebille emile at fenx.com
Sat Sep 1 00:04:25 EDT 2001


>>> l = ['this','is','a','test,']
>>> nl = [x.capitalize() for x in l]
>>> nl
['This', 'Is', 'A', 'Test,']

HTH,

--

Emile van Sebille
emile at fenx.com

---------
"Tyler Eaves" <tyler at tylereaves.com> wrote in message
news:jMYj7.2236$l8.153157 at newsread1.prod.itd.earthlink.net...
> FMH wrote:
>
> > 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.
>
> Well, there is the hacky and ugly way :)
>
> list1=['foo','bar']
> list2=[]
> for x in list1[:]:
>         list2.append(string.dosomething(x))
>
>
>
>




More information about the Python-list mailing list