Hi,

On 15 June 2011 19:56, smichr <[email protected]> wrote:

> What is the rationale for the differences in these two keys:
>
>    >>> sorted([x, a, b], key=default_sort_key)
>    [a, b, x]
>    >>> sorted([x, a, b], key=Basic.sort_key)
>    [x, a, b]
>

In [1]: default_sort_key(x)
Out[1]: ((2, 0, Symbol), (1, (x,)), ((1, 0, Number), (0, ()), (), 1), 1)

In [2]: Basic.sort_key(x)
Out[2]: ((2, 0, Symbol), (0, ()), ((1, 0, Number), (0, ()), (), 1), 1)

In [3]: Expr.sort_key(x)
Out[3]: ((2, 0, Symbol), (1, (x,)), ((1, 0, Number), (0, ()), (), 1), 1)

In [4]: Atom.sort_key(x)
Out[4]: ((2, 0, Symbol), (1, (x,)), ((1, 0, Number), (0, ()), (), 1), 1)

sort_key() is an instance method, so if you call it like this, you override
method resolution algorithm and use wrong method for the type. Also note
that default_sort_key uses sympify() on its argument (irrelevant in this
case). [3] and [4] give the same result because Expr.sort_key() contains
redundant implementation for atoms.


>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.
>
>
Mateusz

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to