On Sun, Apr 21, 2019 at 11:36 PM G. M.-S. <lists....@gmail.com> 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 module named natsort

install it using pip; quit Sage and run (in Sage's root directory):

./sage --pip install natsort

now this works:
./sage
...

sage: from natsort import natsorted
sage: a = ['2 ft 7 in', '1 ft 5 in', '10 ft 2 in', '2 ft 11 in', '7 ft 6 in']
sage: natsorted(a)
['1 ft 5 in', '2 ft 7 in', '2 ft 11 in', '7 ft 6 in', '10 ft 2 in']
sage:


>
> On Sun, 21 Apr 2019 at 23:59, Nils Bruin <nbr...@sfu.ca> wrote:
>>
>> 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 substrings and make a tuple of strings and 
>> integers out of it and sort that).
>
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sage-support+unsubscr...@googlegroups.com.
> To post to this group, send email to sage-support@googlegroups.com.
> Visit this group at https://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to