开发者

sorting list in python accoeding to one dimension [duplicate]

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜