Python的map函数
map函数简介
def square(x):
return x*x
print map(square, [1, 2, 3, 4, 5, 6, 7, 8, 9])[1, 4, 9, 10, 25, 36, 49, 64, 81]print map(lambda x: x ** 2, [1, 2, 3, 4, 5, 6, 7, 8, 9])输入:['adam', 'LISA', 'barT']
输出:['Adam', 'Lisa', 'Bart']def format_name(s):
s1 = s[0:1].upper() + s[1:].lower()
return s1
print map(format_name, ['adam', 'LISA', 'barT'])map函数进阶
参考
Last updated