Modifying the {} and [] tokens

Just just at xs4all.nl
Sun Aug 24 03:57:07 EDT 2003


In article <Zi6dnd57h5jI-tWiXTWJkA at comcast.com>,
 "Terry Reedy" <tjreedy at udel.edu> wrote:

> "> If you can conjure up the right Google Groups query, this has been
> discussed
> > many times in the past (and by that I mean some good points have
> been raised
> > that you might find interesting). In particular, I remember Alex
> Martelli
> > making a good argument for len(obj) over obj.len().
> 
> One point someone made is summarized by the following contrast:
> 
> collections = (atuple, alist, adict, someothercollection)
> flengths = map(len, collections) #actual
> mlengths = map(lambda obj: gettattr(obj, 'len')(), collections)
> #hypothetical

Uh?
  mlengths = map(lambda obj: obj.len(), collections)

> # or listcomp equivalents

That would be much better than the lambda version:
  mlengths = [x.len() for x in collections]

Just




More information about the Python-list mailing list