[Python-Dev] defaultdict and on_missing() (original) (raw)
Terry Reedy tjreedy at udel.edu
Wed Mar 1 08:29:44 CET 2006
- Previous message: [Python-Dev] iterator API in Py3.0
- Next message: [Python-Dev] defaultdict and on_missing()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Greg Ewing" <greg.ewing at canterbury.ac.nz> wrote in message news:44052636.9090709 at canterbury.ac.nz...
And you don't think there are many different types of iterables? You might as well argue that we don't need len() because it "only applies to sequences".
Since you mention it..., many people have asked on c.l.p why len() is a builtin function rather than a method of sequences (and other collections) (as .len, not .len). Some have suggested that it should be the latter. The answers justifying the status quo have been twofold.
- Before 2.2, not all builtin sequence types had methods (str and tuple), so they could not have a .len method. (This begs the question of why not, but that is moot now.)
- whereas .next came in with the universalization of methods.
- Before the addition of list comprehensions, a function could be mapped much more easily than a method
whereas now we do have list comps and even this works
[i.add(2) for i in range(3)] [2, 3, 4]
I can imagine wanting to map len to, for instance, a list of strings more easily than I can imagine a reason to map next/.next to a list of iterators, and if I did, I am willing to use the list comp form.
Terry Jan Reedy
- Previous message: [Python-Dev] iterator API in Py3.0
- Next message: [Python-Dev] defaultdict and on_missing()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]