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 - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -