sorted(L, key=lambda v: (v[:1],int(v[1:])))
would do the trick. In general, you could look at something like
https://pypi.org/project/natsort/. It might be able to make a more natural
sortkey in more examples (in general, the idea would be to split your
string in alphabetic and numerical substr
Thank you very much, Nils.
As I have a list of variables, I changed it to
sorted(L, key=lambda v: (str(v)[:1],int(str(v)[1:])))
Another question: How can I get natsort?
from natsort import natsorted
gives
ImportError: No module named natsort
On Sun, 21 Apr 2019 at 23:59, Nils Bruin wrote:
>
On Sun, Apr 21, 2019 at 11:36 PM G. M.-S. wrote:
>
>
> Thank you very much, Nils.
>
> As I have a list of variables, I changed it to
>
> sorted(L, key=lambda v: (str(v)[:1],int(str(v)[1:])))
>
> Another question: How can I get natsort?
> from natsort import natsorted
> gives
> ImportError: No mod
Thank you, Dima.
This does not work for me. I get
$ ./sage --pip install natsort
pip is configured with locations that require TLS/SSL, however the ssl
module in Python is not available.
I think I have to install openssl first. I shall give it a try later.
Guillermo
On Mon, 22 Apr 2019 at 11
Having defined
sage: x = SR.var('x', 20)
sage: a = [x[11], x[8], x[10], x[9]]
sorting by repr or by str is disappointing:
sage: sorted(a, key=repr)
[x10, x11, x8, x9]
sage: sorted(a, key=str)
[x10, x11, x8, x9]
As Dima suggests, one can
./sage --pip install natsort
On Monday, April 22, 2019 at 11:03:48 AM UTC-7, slelievre wrote:
>
> Having defined
>
> sage: x = SR.var('x', 20)
> sage: a = [x[11], x[8], x[10], x[9]]
>
> sorting by repr or by str is disappointing:
>
> sage: sorted(a, key=repr)
> [x10, x11, x8, x9]
>
> sage: sorted(a, key=s
Mon 2019-04-22 19:23:32 UTC, John H Palmieri:
>
> Alternatively, you should be able to download
> a tar.gz file from https://pypi.org/project/natsort/#files, and then do
>
> ./sage --pip install /path/to/natsort-6.0.0.tar.gz
Thanks for the reminder! I often forget one can download
the tarball ones
So I got the tarball and it got installed but complaining still about SSL
(why?):
$ ./sage --pip install /src/natsort-6.0.0.tar.gz
pip is configured with locations that require TLS/SSL, however the ssl
module in Python is not available.
Processing /src/natsort-6.0.0.tar.gz
Installing collected
It works with strings:
sage: natsorted(a,key=*lambda* z:str(z))
[x8, x9, x10, x11]
Thank you to all of you for your help.
On Mon, 22 Apr 2019 at 22:56, G. M.-S. wrote:
>
> So I got the tarball and it got installed but complaining still about SSL
> (why?):
>
> $ ./sage --pip install /src/natso
Mon 2019-04-22 21:08:55 UTC, G. M.-S.:
>
>
> It works with strings:
>
> sage: natsorted(a,key=*lambda* z:str(z))
>
> [x8, x9, x10, x11]
>
... which can be simplified to
sage: natsorted(a, key=str)
--
You received this message because you are subscribed to the Google Groups
"sage-support"
10 matches
Mail list logo