开发者

sorting list in python accoeding to one dimension [duplicate]

开发者 https://www.devze.com 2023-01-31 02:33 出处:网络
This question already has answers here: Closed 12 ye开发者_开发百科ars ago. Possible Duplicate: Sorting a tuple that contains tuples
This question already has answers here: Closed 12 ye开发者_开发百科ars ago.

Possible Duplicate:

Sorting a tuple that contains tuples

hi

I have a list that goes A=[[a,'3'],[g,'1'],[y,2]]

I am looking for a quick way to arrange it according to the numbers (second dimension), so

NewA=[[g,'1'],[y,'2'],[a,'3']]

thanks

ariel


from operator import itemgetter
newA = sorted(a, key=itemgetter(1))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号