python STL?

Dave Brueck dave at
Fri Nov 14 22:24:42 CET 2003

xam wrote:
> "Dave Brueck" <dave at> wrote in message
> news:mailman.747.1068842483.702.python-list at
> > > being recently introduced to the joys of programming in a powerful
> > > dynamic language (go snake!) I periodically rethink which parts of C++ I
> > > still miss. One thing I really enjoy is the generics of C++ - i think
> > > they are the single strong benefit of a strongly typed system. I was
> > > wondering about the possibility of implementing STL-like algorithms in
> > > Python and the one thing that I cannot think of doing without a kludge
> > > is the object comparsion that so much of STL relies on, which in turn
> > > relies on types and function(<) overloading. Is there a way to implement
> > > something similar in python (short of multimethods?). How does the
> > > python dictionary object allow arbitrary key types? Is in internally
> > > using the references' addresses to impose the tree ordering?
> > > thanks,
> > > max.
> >
> > Hi Max,
> >
> > Could you give a more specific example of what you miss?
> std::sort - works on any well-ordered object collection (you just define
> your own operator< if you need to sort based on some weird criteria)

Right - this is what I suspected: most of the C++ STL _functionality_ is
available in Python already. Not all of it, but at least what I find to be the
most useful stuff (and in general if it's not built-in it's "almost" built-in
in that it's trivial to implement, so much so that having a Python STL wouldn't
make sense).

For example, Python's standard sort() already works on object collections, and
you could define your own comparison method if you want.


More information about the Python-list mailing list