Discuss / Python / 作业

作业

Topic source

bai渡者

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

#请用sorted()对上述列表分别按名字排序:

-- coding: utf-8 --

L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]

def by_name(t): return t[0]

L2 = sorted(L, key=by_name) print(L2)

#再按成绩从高到低排序:

-- coding: utf-8 --

L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]

def by_score(t): return -t[1]

L2 = sorted(L, key=by_score) print(L2)

return -t[1] 天才!

请问return -t[1] 该如何理解?

有个问题请教一下, 在WIN10系统上安装的Python和Notepad++,用Note保存的py格式结尾的('Hello,world'),文件的图标是大E,cmd无法执行,出来的结果是浏览器print('Hello,world'),打开方式修改不了

麻烦协助解决,感谢!


  • 1

Reply