这里是我的问题,我有tuple1=[(1, 3), (3, 2), (2, 1)]
我想根据每个元组这样的结果会是这样 output=[(2, 1), (3, 2), (1, 3)]
低于 的最后一位数字进行排序元组是我的代码Python的元组排序基于最后一个元素上
i=0
for x in tuples:
c.append(x[len(x)-1])
last=sorted(c)
for y in last.iteritems():
if(y in x[len(x)-1]):
print x
#b.insert(i,x)
i=i+1
运行IAM收到错误讯息后
Traceback (most recent call last):
File "x.py", line 47, in <module>
sort_last([(1, 3), (3, 2), (2, 1)])
File "x.py", line 35, in sort_last
if(y in x[len(x)-1]):
TypeError: argument of type 'int' is not iterable
我的不好,这个问题不是关于排序,但解决方案是相同的:指定“键”功能,以“排序”或“排序”。 – 2013-02-12 09:32:06