[portland] Extracting strings from a tuple

Jeff Schwaber freyley at gmail.com
Sat Nov 3 00:03:11 CET 2007

[a[0][i] for i in range(len(a[0]))]

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[0][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?
> Rich
> --
> 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
> http://mail.python.org/mailman/listinfo/portland

More information about the Portland mailing list