On 6 16 , 2 06 , "BJörn Lindqvist" <[EMAIL PROTECTED]> wrote: > > Maybe you could extend count() analogous to how sort() works: > > # L is a list of Person objects, each Person has a name attribute > L.sort(key = attrgetter("name")) > > # How many olle are there? > print L.count("olle", key = attrgetter("name")) > > # And index could be extended in the same way! > # Whom has id 1234? > print L.index(1234, key = attrgetter("id")).name > > All of these could be solved by giving Person an __eq__() method, but > it fails when you need to search, sort or count on a different key. > > -- > mvh Björn
Wow! This jumps out of my screen! I like it very much. How to get the extension into the language? cheers, Ping p.s. By the way, I guess you meant print L[L.index(1234, key = attrgetter("id"))].name in the index example.
-- http://mail.python.org/mailman/listinfo/python-list