Hi Vincent Delecroix, > There is a difference at the interpreter level, look at : > sage: timeit('len(l)') > 625 loops, best of 3: 229 ns per loop > sage: timeit('l.__len__()') > 625 loops, best of 3: 442 ns per loop > > I don't know exactly why. Perhaps the len() do not have to parse the > list of methods of the object ?
I'd guess : some python internal optimization for basic datatype. I.e. if l is a list the python interpreter looks directly into to data structure without calling .__len__() but it's special to lists. > I really agree that the case of words is really special. A word has a > length but no cardinality. Perhaps it's the same for other > combinatorial object (but no combinatorial classes). And I think that > a word is more a combinatorial object. For combinatorial objects, in the "real life" (ie talk/course) as well as in MuPAD, we use to call this the size of the object. Eg: the size of a the permutations [3,1,2,5,4] is 5, the size of the partitions (3,2,1,1,1) is 8, the size of a tree is its number of node... > If we choose something for combinatorial classes the count is not so > bad, because a combinatorial class is not a list (there is no > repetition). It is not clear for me and in some case wrong... Some combinatorial class are multisets. Cheers, Florent --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---