Python - sorting a list -


this question has answer here:

i started playing list , know.

if have data in list in format ['john 1', 'jack 2']

how sort them number?

you can pass key sorted function extracts number splitting on space , converts integer.

a = ['john 2', 'jack 1']  print(sorted(a, key=lambda x:int(x.split(' ')[-1]))) # ['jack 1', 'john 2'] 

Comments

Popular posts from this blog

java - Unable to make sub reports with Jasper -

sql - The object name contains more than the maximum number of prefixes. The maximum is 2 -

scala - play framework: Modules were resolved with conflicting cross-version suffixes -