我可以在列表中对列表进行排序时访问它吗list.sort()
b = ['b', 'e', 'f', 'd', 'c', 'g', 'a']
f = 'check this'
def m(i):
print i, b, f
return None
b.sort(key=m)
print b
这返回
b [] check this
e [] check this
f [] check this
d [] check this
c [] check this
g [] check this
a [] check this
请注意,列表的各个项目b
被发送到 function m
。但是在m
listb
是空的,但是它可以看到与f
list 具有相同范围的变量b
。为什么函数m
打印b
为[]
?