len() and __len__

Chris Liechti cliechti at gmx.net
Sun May 26 12:10:43 EDT 2002


Artur Siekielski <gruesome at go2.pl> wrote in 
news:slrnaf16hh.h0.gruesome at muyc.omput.er:

> Is there any difference between len(a) and a.__len__() in Python 2.2?

no len() calls __len__

but you can do
>>> listoflength = map(len, somelist)

which isn't that simple with __len__():

>>> listoflength = []
>>> for x in somelist:
...    	listoflength.append(x.__len__())

chris

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list