Discuss / Python / key函数作用于list每一个元素上面,return t[0:] 很好理解,但是return t[::1]是什么意思呢?

key函数作用于list每一个元素上面,return t[0:] 很好理解,但是return t[::1]是什么意思呢?

Topic source

帛子先生

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

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

-- coding: utf-8 --

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

return t[0:]    
#return t[::1]为什么可以替换这个?

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


  • 1

Reply