[portland] zip() tutorial needed

Rich Shepard rshepard at appl-ecosys.com
Mon Mar 31 23:58:57 CEST 2008


On Mon, 31 Mar 2008, Dylan Reinhardt wrote:

> Your immediate problem is that your list is a *collection* of two-element
> tuples. You are trying to unpack the *list* and what you want to do is
> unpack each *element*.  Ex:
>
> mylist = [(15.0, 0.0), (30.0, 1.0), (70.0, 1.0), (85.0, 0.0)]
> for x,y in mylist:
>    doSomething(x)
>    doSomething(y)

Dylan,

   That was the original problem, and your explanation makes it perfectly
clear. Especially with the for loop showing an alternate approach.

> I'm not a huge fan of zip... I think it tends to make code less readable,
> but YMMV.

   Obviously, I'm not a fan of structures I don't understand. But, there's so
much to Python and I'm learning as I code this application.

Many thanks,

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