Sorting list (maybe stupid)

Delaney, Timothy tdelaney at avaya.com
Tue Jun 11 20:49:59 EDT 2002


> From: Ken Seehof [mailto:kseehof at neuralintegrator.com]
> 
> >>> a = [1,1.0,3.0,3,2.0,2,0,0.0]
> >>> a
> [1, 1.0, 3.0, 3, 2.0, 2, 0, 0.0]
> >>> a.sort()
> >>> a
> [0, 0.0, 1, 1.0, 2.0, 2, 3.0, 3]
> 
> So yes, sort() is stable.

That's a rather small set of data to base that on ...

> I suppose it's theoretically possible for a different
> python implementation to use a different sort algorithm,
> but practically speaking, that is very unlikely.

In fact, the current implementation uses an optimised quicksort IIRC - not
at all stable.

Personally, I think the implementation should be documented to use a stable
sort - presumably mergesort (stable, minimal number of comparisons which is
very important in Python).

Tim Delaney





More information about the Python-list mailing list