A patch to support L.count(value, cmp=None, key=None)
BJörn Lindqvist
bjourne at gmail.com
Mon Jun 18 21:17:22 CEST 2007
> I patched Objects/listobject.c to support
> L.count(value, cmp=None, key=None).
> I tested it with the same script above by replacing slist
> with built-in list. It worked correctly with this small
> test. The patch is below (126 lines, I hope that's not
Great! If you want this change included in Python, you should post it
on SourceForge's patch tracker at
http://sourceforge.net/tracker/?group_id=5470&atid=305470. Optionally,
you can also ask if people like the patch on python-dev. But IMHO, the
odds of this patch being accepted are slim (borrowing from the example
in the last thread):
persons.count("olle", key = attergetter("name"))
is longer and just barely more readable than
sum(1 for x in persons if x.name == "olle"))
--
mvh Björn
More information about the Python-list
mailing list