[portland] Still Having List/Tuple Problems

Rich Shepard rshepard at appl-ecosys.com
Wed Apr 16 21:14:43 CEST 2008


On Wed, 16 Apr 2008, jason kirtland wrote:

> # option 2) make groups, each sharing a common 'left' item
> from itertools import groupby
> from operator import itemgetter
>
> for left, grouped in groupby(list_o_tuples, itemgetter(0)):
>     print left
>     for left_again, right in grouped:
>         print "\t", right
>
> # look under the hood at what groupby() does in 2)
> for left, grouped in groupby(list_o_tuples, itemgetter(0)):
>     print left, list(grouped)

   Thanks, Jason. I obviously still don't fully understand 'groupedby', but
This is what I need to create nested for loops.

   Hope it sticks this time!

Rich

-- 
Richard B. Shepard, Ph.D.               |  Integrity            Credibility
Applied Ecosystem Services, Inc.        |            Innovation
<http://www.appl-ecosys.com>     Voice: 503-667-4517      Fax: 503-667-8863


More information about the Portland mailing list