[Python-ideas] Proposal for extending the collections module - bags / multisets, ordered sets / unique lists
Michael Lenzen
m.lenzen at gmail.com
Sat Jul 18 22:54:39 CEST 2009
On 07/18/2009 03:19 PM, Leonardo Santagada wrote:
>
> I was silent on this because I wanted someone that has a say in this
> stuff to stop it but as you really think this is important I have to
> point out that this function is probably unaceptable, it makes code that
> much harder to read (instead of set or list I have to see each parameter
> and form on my mind what they map to) and also GvR already said before
> that he doesn't like functions that have flags that make them do
> completely different things based on those.
>
> Multiset seems interesting, some of the ABCs you mentioned seems to be
> just over engineering (maybe they just need a better justification) but
> this function in my view is unacceptable.
>
> --
> Leonardo Santagada
> santagada at gmail.com
>
>
>
Thanks, this is why I posted here before I proposed anything formally, I
wasn't aware of the precedence. Maybe I didn't explain it clearly
enough, or maybe I'm just wrong.
The Collection ABC was mostly to unify operations of the different
collections for the collection function, so that a generic collection
returned by the collection function meant something, you wouldn't have
to look back to see how it will perform. For example all collections
would have to provide a count(elem) method, or all mutable collections
could have to provide add and remove methods.
I don't understand how this code becomes unreadable.
> hand = collection(ordered=False, unique=False)
> for i in range(5):
> hand.add(deck.pop_card())
> for card in cards:
> if hand.count(card) == 2:
> print('You have a pair.')
-Michael Lenzen
More information about the Python-ideas
mailing list