Specific sort a list of numbers separated by dots

sort comma separated list excel
sort comma separated list online
sort comma separated list unix
unix sort by column delimiter
man sort
cat sort
linux sort multiple columns
linux sort by column

I have a list:

L = ['1.1.1.', '1.1.10.', '1.1.11.', '1.1.12.', '1.1.13.', '1.1.2.', '1.1.3.', '1.1.4.']

I want to sort it in next order:

1.1.1.
1.1.2.
1.1.3.
1.1.4.
1.1.10.
1.1.11.
1.1.12.
1.1.13.

The following method does not produce a result:

L.sort(key=lambda s: int(re.search(r'.(\d+)',s).group(1)))

Just get the last part, convert that to an int and return it as the key for comparison

print(sorted(L, key=lambda x: int(x.split(".")[2])))

If you want all the parts to be considered, you can do like this

print(sorted(L, key=lambda x: [int(i) for i in x.rstrip(".").split(".")]))

It removes . at the end of the strings, splits them based on . and then converts each and every part of it to an int. The returned list will be used for comparison.

You can read more about how various sequences will be compared by Python, here

Output

['1.1.1.','1.1.2.','1.1.3.','1.1.4.','1.1.10.','1.1.11.','1.1.12.','1.1.13.']

Sorting a list of dot-separated numbers, like software versions , Split each version string to compare it as a list of integers: versions_list.sort(key= lambda s: map(int, s.split('.'))) Gives, for your list: ['1.0.0', '1.0.2'� Character separated numbers is a specific type of character-separated values (CSV). It is a delimited text that uses commas or other specific characters to separate numbers. This data format has been used for many years with numerous applications.


If you need to sort by all digits, produce a sequence of integers in the key function:

sorted(L, key=lambda v: [int(p) for p in v.split('.') if p.isdigit()])

This method is robust in the face of non-digit values between the dots.

Demo:

>>> L = ['1.1.1.', '1.1.10.', '1.1.11.', '1.1.12.', '1.1.13.', '1.1.2.', '1.1.3.', '1.1.4.']
>>> sorted(L, key=lambda v: [int(p) for p in v.split('.') if p.isdigit()])
['1.1.1.', '1.1.2.', '1.1.3.', '1.1.4.', '1.1.10.', '1.1.11.', '1.1.12.', '1.1.13.']

Your specific attempt only returns the second number in the list, which for your sample data is always 1.

How can I numerically sort a single line of delimited items?, add -u to the sort command above to remove the duplicates. uses POSIX parameter substitution to find the specific delimiter on each line, (stored in It's restricted to sorting positive integers delimited by dots, but it's not limited to the size of� Converting a List<String> to a String with all the values of the List comma separated in Java 8 is really straightforward. Let’s have a look how to do that. In Java 8.


Use https://pypi.org/project/natsort/3.3.0/ or a similar library for comparing software versions.

Sort comma-separated fields on each line by numeric value, sort operates on entire lines. By default, it sorts on the entire contents of that line, but -k can be used to sort on one or more fields within those lines. -t can be� Enter the size of the list 5 Enter the list numbers separated by space 10 20 30 40 50 User List: [10, 20, 30, 40, 50] Program 4: Using the map function Let’ see how to use the map() function to get a list as an input from the user.


How to sort list of numbers separated by commas in Excel?, To sort comma separated values in a cell, you need to separate the numbers into separated cells first by Text to column, transpose them to a list, and then sort. 1. Here, join() is used to print out individual items in the list separated by the specified format. The format must be enclosed within quotes. In the first case, we’ve separated individual items by a space, in the second case, by two dashes, in the third, by three dots, and in the fourth, by a comma and a space.


Sort numeric strings in a list in Python, Sorting list is an easy task and has been dealt with in many situations. sometimes we can get the data in the format of list of numbers but with string as data type. specified with the key as integer to convert it to integer while performing sort� However when these numbers are in character field, such as char or varchar, the sort becomes alphabetic and the ordering not what we may wish: 1,10,11,15,2,20,21,5,7. For numerals in a text field we could easily convert the values to numeric values and sort; however, this option isn’t available if the column values contain alphanumeric values.


Print number in ascending order which contains 1, 2 and 3 in their , Given an array of numbers, the task is to print those numbers in ascending order separated by commas which have 1, 2 and 3 in their digits. If no number� Convert a List<String> in a String with all the values of the List comma separated using Java 8 is really straightforward. Let’s have a look on how to do that. Let’s have a look on how to do that.