You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to submit a feature request to add an option that would allow natsorted() to sort by letters first, then numbers instead of numbers first, then letters. Here is an example of the list that I am looking to sort - I am sorting by index 2 ('ABCDE', 'BCDEF' and '10001'):
fromnatsortimportnatsorteda= [
['192.168.1.1', 'generic_description_1', 'ABCDE', 'apples', '172.16.1.1', u'\nCircuit is up\n'],
['192.168.1.1', 'generic_description_2', 'BCDEF', 'oranges', '172.16.2.1', u'\nCircuit is up\n'],
['192.168.2.1', 'generic_description_3', '10001', 'bananas', '172.16.3.1', u'\nCircuit is up\n']
]
print(natsorted(a, key=lambdax: x[2]))
Here are the results that are printed:
[['192.168.2.1', 'generic_description_3', '10001', 'bananas', '172.16.3.1', u'\nCircuit is up\n'],
['192.168.1.1', 'generic_description_1', 'ABCDE', 'apples', '172.16.1.1', u'\nCircuit is up\n'],
['192.168.1.1', 'generic_description_2', 'BCDEF', 'oranges', '172.16.2.1', u'\nCircuit is up\n']]
And as you can see, it sorts by index 2 by numbers first, then letters:
10001
ABCDE
BCDEF
The option I am requesting would allow the sorting by letters first, then numbers - like this:
ABCDE
BCDEF
10001
Thanks for the consideration!
-Matt
The text was updated successfully, but these errors were encountered:
This is a good request. The only reason natsort currently puts numbers first is that it was the easier thing to do and I made the assumption that that is what users would want. The process of maintaining this library has taught me that either my assumptions are always wrong, or not to make assumptions.
I'd like to submit a feature request to add an option that would allow natsorted() to sort by letters first, then numbers instead of numbers first, then letters. Here is an example of the list that I am looking to sort - I am sorting by index 2 ('ABCDE', 'BCDEF' and '10001'):
Here are the results that are printed:
And as you can see, it sorts by index 2 by numbers first, then letters:
10001
ABCDE
BCDEF
The option I am requesting would allow the sorting by letters first, then numbers - like this:
ABCDE
BCDEF
10001
Thanks for the consideration!
-Matt
The text was updated successfully, but these errors were encountered: