我想写一个函数
我有一个列表或元组:
alist =[('Carlos', 1), ('Gretchen', 8), ('Abby', 6),('Sam', 4)]
到目前为止,我已经列出了所有的数字,按照代码的顺序排列:
def party_time(alist,maxnum):
newlist = []
finallist=[]
while len(finallist) < maxnum:
for tup in alist:
rank = tup[1]
newlist.append(rank)
newlist.sort()
newlist = [1,4,6,8]
有没有办法使用for循环遍历newlist
并使用newlist
中的数字对元组进行索引?或者它只是索引元组中数字的位置?你知道吗
这应该做到:
相关问题 更多 >
编程相关推荐