I
I
Iskander Mammadov2014-05-01 09:17:17
Python
Iskander Mammadov, 2014-05-01 09:17:17

How to sort a set array of strings in Python?

The program is given 100 lines of similar content as input, all words in the line are separated by spaces:
<Last name> <grade1> <grade2> <grade3>
How to sort this set by <grade2> for example?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rostislav Grigoriev, 2014-05-01
@Gugr

score_list = [u'Иванов 4 4 3', u'Петров 5 3 4']
score_list.sort(key=lambda x: int(x.split(' ')[2]))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question