[portland] Extracting strings from a tuple
freyley at gmail.com
Sat Nov 3 00:03:11 CET 2007
[a[i] for i in range(len(a))]
To unpack that, it's a list comprehension which look like this:
[a for a in listofthings ]
or equivalent to
for a in listofthings:
newlist += a
but this one is a[i] which gets into the list and then into the tuple.
On 11/2/07, Rich Shepard <rshepard at appl-ecosys.com> wrote:
> While this should be simple, I cannot get it working and would appreciate
> guidance on solving my problem.
> There is a database table with a single record. When I retrieve that
> record I have a list consisting of a single tuple. However, that tuple has 7
> strings; when printed it looks like this:
> [(u'string 1', u'string 2', u'string 3', u'string 4', u'string 5', u'string
> 6', u'string 7')]
> What I want to do is walk through that tuple and extract each string.
> However, I cannot successfully slice it, iterate through it, or use an index
> to extract each string. According to "DIP," "Byte of Python," and other
> books I should be able to get each string as a separate item.
> What have I missed?
> Richard B. Shepard, Ph.D. | The Environmental Permitting
> Applied Ecosystem Services, Inc. | Accelerators(TM)
> <http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
> Portland mailing list
> Portland at python.org
More information about the Portland