[portland] Still Having List/Tuple Problems
kirby.urner at gmail.com
Thu Apr 17 03:09:27 CEST 2008
On Wed, Apr 16, 2008 at 4:49 PM, kirby urner <kirby.urner at gmail.com> wrote:
> On Wed, Apr 16, 2008 at 4:24 PM, Rich Shepard <rshepard at appl-ecosys.com> wrote:
> def graphit(groups):
> for key in groups.keys(): # loop through indexes
PS: per David Goodger's "idiomatic Python" at OSCON last year,
it'd be preferable to just go:
for key in groups: # loop through indexes
i.e. as iterables, dictionaries already have a default "step though"
behavior, which is to go through the keys.
So you don't have to explicitly fire the keys() method, and doing
so is less generic i.e. takes advantage of this being a dictionary,
versus an iterable.
Better to keep the semantics streamlined and go for the generic
form over the special case -- more readable, smoother, whatever
(I agreed with David's thesis).
More information about the Portland