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

Jan Kaliszewski zuo at chopin.edu.pl
Sun Jul 19 21:00:01 CEST 2009


Dnia 19-07-2009 o 03:24:38 Steven D'Aprano <steve at pearwood.info>  
napisał(a):

> On Sun, 19 Jul 2009 06:45:46 am Mathias Panzenböck wrote:
>> I don't understand what's so bad about such a collection factory. As
>> a programmer I don't care what class an object is. I just want an
>> object that behaves a certain way. E.g. I want to say: I need a
>> random accessible collection, or I need a collection with unique
>> entries, or I need a collection with a fast (near to O(1)) way to
>> append elements, or all of the above. What class this object will
>> have I don't care.
>>
>> Where is the problem?
>
>
> The problem is that you *do* need to care what the class is, because
> different classes have different interfaces:

It could be a factory similar to namedtuple: creating not objects of
container type, but container types:

OrdSet = collection(ordered=True, unique=True)

numbers = OrdSet([1, 2, 3 ,4 ,5])
letters = OrdSet(['x', 'y', 'z'])
names = OrdSet(['Ann', 'Berta', 'Claude', 'Danuta'])

-- 
Jan Kaliszewski <zuo at chopin.edu.pl>



More information about the Python-ideas mailing list