本文介绍了在python列表中对元组进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有任何简单的方法可以在python列表中对元组进行排序,例如,如果我有一个列表:
i was wondering if there was any simple way around sorting tuples in lists in python, for instance if i have a list:
list01 = ([a,b,c],[b,a,d],[d,e,c],[a,f,d])
我对它进行了排序,我得到了:
and i sorted it, i would get:
([a,b,c],[a,b,d],[c,d,e],[a,d,f])?
甚至:
([a,b,c],[a,b,d],[a,d,f],[c,d,e])
如果更容易
先感谢:)
推荐答案
>>> list01 = (['a','b','c'],['b','a','d'],['d','e','c'],['a','f','d'])
>>> map(sorted, list01)
[['a', 'b', 'c'], ['a', 'b', 'd'], ['c', 'd', 'e'], ['a', 'd', 'f']]
>>> sorted(map(sorted, list01))
[['a', 'b', 'c'], ['a', 'b', 'd'], ['a', 'd', 'f'], ['c', 'd', 'e']]
这篇关于在python列表中对元组进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!