Re: Converting List of Tuples to List of Strings

Rich Shepard <[email protected]>
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
On Wed, 28 Feb 2007, Jim Vickroy wrote:

>>>> x = [(u'Jobs',), (u'Infrastructure',), (u'Housing',), (u'Tax Base',), 
> (u'Traffic Volume',), (u'Roads',), (u'Medical care',), (u'Sustainability',)]
>>>> x
> [(u'Jobs',), (u'Infrastructure',), (u'Housing',), (u'Tax Base',), (u'Traffic 
> Volume',), (u'Roads',), (u'Medical care',), (u'Sustainability',)]
>>>> y = [this[0] for this in x] # retain only the first element of each tuple 
> in *x*
>>>> y
> [u'Jobs', u'Infrastructure', u'Housing', u'Tax Base', u'Traffic Volume', 
> u'Roads', u'Medical care', u'Sustainability']

Jim,

   This is close, but I get the entire list with each of the other values.
Martin pointed out what I forgot: the second index of [0]. I should know
that by now, but I keep forgetting!

Thanks,

Rich

-- 
Richard B. Shepard, Ph.D.               |    The Environmental Permitting
Applied Ecosystem Services, Inc.        |          Accelerator(TM)
<http://www.appl-ecosys.com>     Voice: 503-667-4517      Fax: 503-667-8863
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.