On Thu, May 8, 2008 at 2:04 AM, Carlo Hamalainen <[EMAIL PROTECTED]> wrote: > > On Wed, May 7, 2008 at 5:44 PM, William Stein <[EMAIL PROTECTED]> wrote: > > That's definitely a bug. We are tracking it here: > > http://trac.sagemath.org/sage_trac/ticket/3124 > > Also I found that the variables were not coming back in alphabetical > order. The problem seems to be with sort(): > > sage: var('a, b, c, d') > (a, b, c, d) > sage: x = [a, b, c, d, a] > sage: x.sort() > sage: x > [a, b, c, d, a] > > That's weird. But this works: > > sage: x.sort(key=str) > sage: x > [a, a, b, c, d] > > So what is Python sorting on? It should be calling __cmp__() which > then calls _repr_(), and that just returns _name. But that's exactly > what __str__ calls.
Python is probably *not* calling cmp. Note that: sage: var('x,y') (x, y) sage: x < y x < y I.e., comparison of symbolic objects results in a symbolic equation. This is likely confusing the default for the python sort function. (We should look at the source code if we want to see why.) One can just pass cmp into sort and even that works: sage: cmp(x,y) -1 sage: v = [y,x] sage: v.sort(cmp) sage: v [x, y] I do not consider this a bug. -- William --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---