[portland] Still Having List/Tuple Problems

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

On Wed, 16 Apr 2008, kirby urner wrote:

> You could use list comprensions:

>>>> astuff = [j for (i,j) in mydata if i == 'A']


   I thought of trying this, but I want to make it general rather than
explicit ...

> If you don't know what all the keys are gonna be you could build a list of
> unique ones:

   ... as you show here.

>>>> thekeys = set([i for (i,j) in mydata])
>>>> thekeys
> set(['A', 'C', 'B'])
>>>> for thekey in thekeys:
> 	print thekey
> 	print [j for (i,j) in mydata if i == thekey]

   I need to read and learn about sets in python.

   Now I have two approaches as solutions when I again run into the same

Thank you very much,


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