Sorting using lambda not working in Py2.1?

Brian Kelley kelley at bioreason.com
Sat May 5 09:25:15 EDT 2001


Tim Peters wrote:

> [Brian Kelley]
> > It should be noted that Python 1.5.1 could handle
> > l.sort(lambda x,y: x<y) before the sorting engine was revamped.
>
> This is false.  What was true is that passing x<y used to be more likely to
> work by accident, and especially for small lists.  Python's sort() has
> *always* required a 3-outcome cmp function, and people passing x<y in earlier
> Pythons eventually suffered horrid surprises as their data changed and their
> lists got larger.

Ahh, this is something that wasn't mentioned during the last sorting thread I
started.  I learn something new about the internals every time I mention sorting.

> In a similar vein, the current sort happens to be stable for small lists, but
> isn't stable in general.

What do you mean by stable in this case?

> And contrary to persistent rumor, Guido doesn't
> change things gratuitously <wink>.

Brian This-at-least-I-knew Kelley




More information about the Python-list mailing list