[portland] Iterating Through Tuples In A List

Dylan Reinhardt dylanr at dylanreinhardt.com
Fri Feb 15 21:53:01 CET 2008

On 2/15/08, jason kirtland <jek at discorporate.us> wrote:

> rows = [('HabitatComplexity',2,1,'Decay S-Curve'),
>          ('HabitatComplexity',2,2,'Growth S-Curve'),
>          ('SpecialConcern',3,1,'Decay S-Curve'),
>          ('SpecialConcern',3,2,'Bell Curve'),
>          ('SpecialConcern',3,3,'Growth S-Curve'),
>          ('Variety',2,1,'Decay S-Curve'),
>          ('Variety',2,2,'Growth S-Curve'),]

Ah... that makes more sense.

If that's what you have, you can also do this, if it helps:

grouper = {}
for row in rows:
    grouper.setdefault(row[0], []).append(row[3])
for comp in grouper.keys():
    print comp
    for subcomp in grouper[comp]:
        print ' - ', subcomp


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

More information about the Portland mailing list