language design question

Steven D'Aprano steve at REMOVETHIScyber.com.au
Sun Jul 9 19:36:21 EDT 2006


On Sun, 09 Jul 2006 22:45:53 +0000, OKB (not okblacke) wrote:

> Terry Reedy wrote:
> 
>> Consider
>>>>> map(len, ('abc', (1,2,3), [1,2], {1:2}))
>> [3, 3, 2, 1]
>> 
>> Now try to rewrite this using methods (member functions).
> 
> [a.len() for a in ('abc', (1,2,3), [1,2], {1:2})]

Did you actually try that?

>>> 'abc'.len()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'str' object has no attribute 'len'

In any case, list comprehensions are a recent (version 2.2 I think?)
addition to Python. You have to think about the functionality
available back in the days when the decision to make len() a function was
made, not based on what functionality is available a decade later. 


-- 
Steven.




More information about the Python-list mailing list