在教程中,我看到一段我验证过的代码: https://wiki.python.org/moin/HowTo/Sorting
init = function() {
// Create the bookmarks instance and assign it to the property of book.
this.bookmarks = new bookmarks();
// Tell the bookmarks about me, the book object.
this.bookmarks.book = this;
}
为什么python知道学生[2]引用每个元组的第三个元素?为什么不尝试按第三元组排序,而不是每个元组的第三项?
答案 0 :(得分:2)
因为sorted
函数将其可迭代参数的元素发送到lambda函数。在这种情况下,元组将被发送到lambda
。
key指定一个参数的函数,该函数用于从每个列表元素中提取比较键:key = str.lower。默认值为None(直接比较元素)。