len() and __len__

Hans Nowak wurmy at earthlink.net
Sun May 26 19:26:00 EDT 2002


Chris Liechti wrote:

> but you can do
> >>> listoflength = map(len, somelist)
> 
> which isn't that simple with __len__():
> 
> >>> listoflength = []
> >>> for x in somelist:
> ...     listoflength.append(x.__len__())

Or just

>>> map(lambda x: x.__len__(), ["foo", "bar", "bogus"])
[3, 3, 5]

I agree that len() is cleaner though.

-- 
Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) 
# decode for email address ;-)
The Pythonic Quarter:: http://www.awaretek.com/nowak/



More information about the Python-list mailing list