Ordering python sets

Terry Reedy tjreedy at udel.edu
Sun Oct 26 00:20:46 CEST 2008

Lie Ryan wrote:

> <anotherrandommusing>
> Since python is dynamic language, I think it should be possible to do 
> something like this:
> a = list([1, 2, 3, 4, 5], implementation = 'linkedlist')

For this to work, the abstract list would have to know about all 
implementations of the abstraction.

> b = dict({'a': 'A'}, implementation = 'binarytree')
> c = dict({'a': 'A'}, implementation = 'binarytree')
> i.e. basically since a data structure can have different implementations, 
> and different implementations have different performance characteristics, 
> it should be possible to dynamically change the implementation used.
> In the far future, the data structure and its implementation could be 
> abstracted even further:
> a = list() # ordered list
> b = set() # unordered list
> c = dict() # unordered dictionary
> d = sorteddict() # ordered dictionary
> Each of the implementations would share a common subset of methods and 
> possibly a few implementation dependent method that could only work on 
> certain implementations (or is extremely slow except in the correct 
> implementation).
> </anotherrandommusing>

The future is 3.0, at least in part, with Abstract Base Classes.
There are 16 in the collectons module.
  "In addition to containers, the collections module provides some ABCs 
(abstract base classes) that can be used to test whether a class 
provides a particular interface, for example, is it hashable or a 
mapping, and some of them can also be used as mixin classes."

The ABCs for numbers are in the numbers module.


More information about the Python-list mailing list