[Python-ideas] Proposal for extending the collections module - bags / multisets, ordered sets / unique lists

Mike Meyer mwm-keyword-python.b4bdba at mired.org
Sun Jul 19 06:31:48 CEST 2009


On Sun, 19 Jul 2009 11:28:37 +1000
Steven D'Aprano <steve at pearwood.info> wrote:
> >   > for card in cards:
> >   >     if hand.count(card) == 2:
> >   >         print('You have a pair.')
> Why would a class with unique=True have a count() method? 

So that you can write code that doesn't care which of the various
flavors of collection it gets passed, but will work on them
anyway.

It supports a property of classes in OO programming called
"polymorphism". It's a good thing. That python's collections don't
have it has always been a minor wart, and it gets bigger as we get
more types of collections.

     <mike
-- 
Mike Meyer <mwm at mired.org>		http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org



More information about the Python-ideas mailing list