Discuss / Python / 作业

作业

Topic source

YondMars

#1 Created at ... [Delete] [Delete and Lock User]

第一题:

L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]
def by_score(t):
    return t

L2 = sorted(L,key = by_score)

print(L2)

第二题:

L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]
def by_score(t):
    return t[::-1]

L2 = sorted(L,key = by_score)

print(L2)

jhgyz

#2 Created at ... [Delete] [Delete and Lock User]

不是说sorted字符排序是按ASCII码从小到大排序的吗,为什么L中我改成首字母含大小写字母时,不用转换大写或小写再排序就能输出正确呢

jhgyz

#3 Created at ... [Delete] [Delete and Lock User]

理解错了,没有问题


  • 1

Reply