newbie.string.listless

Paul Sidorsky paulsid at home.com
Sat Sep 1 00:07:05 EDT 2001


FMH wrote:

> 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.  

If you like one-liners (and are using Python 2.x), try a list comprehension:

>>> names = ["one", "who", "two", "three"]
>>> capnames = [i.capitalize() for i in names]
>>> print capnames
['One', 'Who', 'Two', 'Three']

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid at home.com                      http://members.home.net/paulsid/




More information about the Python-list mailing list