[portland] Iterating Through Tuples In A List

Dylan Reinhardt dylanr at dylanreinhardt.com
Fri Feb 15 21:40:47 CET 2008


On 2/15/08, Rich Shepard <rshepard at appl-ecosys.com> wrote:
>
>    Data start with a list of tuples. I iterate through the list and
> extract
> each tuple using,
>
> for i in range(len(self.appData.tsets)):
>        self.row = self.appData.tsets[i]


Unless you *really* want to set self.row, I might do this instead:

for row in self.appData.tsets:
    ...

Beyond that, it's not exactly clear what the structure of your tuples is,
but let's say you have the following:

mytup = (
              ('a', (1,2,3), 'b'),
              ('c', (5,6,7,8), 'c')
             )

The second element of each tuple is another tuple.  One way you might
manipulate this is:

for row in mytup:
    print row[0]
    for inner in row[1]:
        print ' - ', inner

That's pretty trivial, but it shows iterating over sub-collections of
unequal length.  Hopefully part of that answers your question.

If that's not helpful, you might want to post a dump of a couple rows of the
tuple you're struggling with.

HTH,

Dylan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/portland/attachments/20080215/de30672c/attachment.htm 


More information about the Portland mailing list