python STL?

Terry Reedy tjreedy at
Sat Nov 15 02:13:34 CET 2003

"Maxim Khesin" <max at> wrote in message
news:0latb.95267$ri.14418352 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++

Then since Python programming generally *is* generic programming, it
is not surprising that you enjoy Python ;-).

> - i think  they are the single strong benefit of a strongly typed

And Python is more strongly typed than C/C++ (no type casts except
possibly for some user classes).

> I was wondering about the possibility of implementing
> STL-like algorithms in Python

>From what I understand of STL, Python functions are STL or template
like unless one specificly adds type checks to inhibit the generality.
Python code works with any object with the needed interface and
behavior.  Perhaps you have not grokked this because it is automatic
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
> relies on types and function(<) overloading.

I do not understand this.  Most builtin types come with working
comparison operations.  User-defined classes can easily include them
also.  I believe the builtin functions max and min are more
general/generic that what you can very easily write in C++.

> Is there a way to implement something similar in python

Probably, but we need an example 'something'.

>How does the python dictionary object allow arbitrary key types?

It accepts any hashable object by using the hash value.

> Is in internally using the references' addresses

CPython uses object addresses, but that is an implementation detail
rather than part of the language definition.  The C source is open and
pretty readable.

> to impose the tree ordering?

There is no tree ordering as I understand the term.

Terry J. Reedy

More information about the Python-list mailing list