sort a list

1,639 views
Skip to first unread message

Mikie

unread,
Jul 15, 2009, 3:14:10 PM7/15/09
to sage-support
How does one sort a list in Sage? I have tried

L1=[56,2,4,10]
Sort_ = L1.sort()

and nothing is produced.

I need it to calculate Quartiles. Is there a Quatile function in any
of the modules?

Thanks
Message has been deleted

Justin C. Walker

unread,
Jul 15, 2009, 3:19:26 PM7/15/09
to sage-s...@googlegroups.com

On Jul 15, 2009, at 12:14 , Mikie wrote:

>
> How does one sort a list in Sage? I have tried
>
> L1=[56,2,4,10]
> Sort_ = L1.sort()
>
> and nothing is produced.

As the saying goes, RTFM :-}

sage: L1=[56,2,4,10]
sage: L1.sort?
Type: builtin_function_or_method
Base Class: <type 'builtin_function_or_method'>
String Form: <built-in method sort of list object at 0x8a586c0>
Namespace: Interactive
Docstring:
L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN
PLACE*;
cmp(x, y) -> -1, 0, 1
Class Docstring:
<attribute '__doc__' of 'builtin_function_or_method' objects>

sage: L1
[2, 4, 10, 56]

HTH

Justin

--
Justin C. Walker, Curmudgeon at Large
Institute for the Absorption of Federal Funds
-----------
If it weren't for carbon-14, I wouldn't date at all.
-----------


Carlos Córdoba

unread,
Jul 15, 2009, 3:26:23 PM7/15/09
to sage-s...@googlegroups.com
This is not about RTFM, because L1.sort() doesn't produce any result. It just modifies the original list in place.

I think that Mikie wants to assign the sorted list to another list. In that case what you need is the sorted command:

sage: L1 = [56,2,4,10]
sage: sort_L1 = sorted(L1)
sage: sort_L1
[2,4,10,56]

Mikie

unread,
Jul 15, 2009, 3:48:21 PM7/15/09
to sage-support
Carlos,
just what I needed.
I have looked in scipy, but no Quartiles.
> > ------------ Hide quoted text -
>
> - Show quoted text -

Simon King

unread,
Jul 15, 2009, 4:47:10 PM7/15/09
to sage-support
Hi!

On 15 Jul., 21:26, Carlos Córdoba <ccordob...@gmail.com> wrote:
> This is not about RTFM, because L1.sort() doesn't produce any result. It
> just modifies the original list in place.

... and this is precisely what the manual tells you.

However, you are right:

> I think that Mikie wants to assign the sorted list to another list. In that
> case what you need is the sorted command:

The "sorted" command is probably the answer to Mikie's question.

Cheers,
Simon
Reply all
Reply to author
Forward
0 new messages