1. max min函数的灵活用法,主要是对max min 函数中 key的灵活定义:
eg. 1: arr = ["abc","abcd","abcde"] 找到 arr中长度最短的字符串:
arr = ["abc","abcd","abcde"]
res = min(arr,key = lambda ele:len(ele)) #等同于: res = min(arr,key=len)
eg. 2: 找到个位最大的元素:
arr=[123,234,345]
res = max(arr,key = lambda ele:ele%10)
2. enumerate 函数的用法:
for i,ch in enumrate("abc"):
print i,ch
0 a
1 b
2 c
解释:以index - value 的形式返回一个可迭代的结果