Sep-25-2019, 06:39 AM
(This post was last modified: Sep-25-2019, 06:39 AM by ToffieFaye.)
Well, that is embarrasing.
Thank you! If I change 2 to 1 it works in the simple example.
Originally I wanted to sort a list out of a file and there it still doesn't work.
I'll show you the whole code. Maybe you can help?
I'd honestly really appreciate that!
So this is the code:
Do you understand that?
Thank you! If I change 2 to 1 it works in the simple example.
Originally I wanted to sort a list out of a file and there it still doesn't work.
I'll show you the whole code. Maybe you can help?
I'd honestly really appreciate that!
So this is the code:
with open('example.txt','r') as textFile2: data_list = [line.split() for line in textFile2] textFile2.close() data_list = sorted(data_list, key=lambda data_list: data_list[1]) print(data_list)and this is how the example.txt file looks like:
16 43 23.5 85.8 17 61 21.1 86.4 18 40 22.5 90.0 19 37 28.5 86.1 20 22 19.4 78.9 21 156 29.2 89.2 22 63 35.4 86.3 23 105 31.3 86.7This is the output:
Output:[['23', '105', '31.3', '86.7'], ['21', '156', '29.2', '89.2'], ['20', '22', '19.4', '78.9'], ['19', '37', '28.5', '86.1'], ['18', '40', '22.5', '90.0'], ['16', '43', '23.5', '85.8'], ['17', '61', '21.1', '86.4'], ['22', '63', '35.4', '86.3']]
It works for the numbers with 2 letters, but it still puts 105 and 156 in the front and I don't know why.Do you understand that?