内置函数

1.map是映射函数

lst = [1,2,3,4,5,6,7]

def func(i):

    return i * i
it = map(func,lst)
print(list(it))
结果>>>[1, 4, 9, 16, 25, 36, 49]

2sorted是排序函数
lst = [3,5,1,14,1,4,13,10,20,2]

lst.sort() #sort是list里面的一个方法
print(lst)
结果>>>[1, 1, 2, 3, 4, 5, 10, 13, 14, 20]
l1=sorted(lst) #内置函数 返回一个新列表,新列表是被排序的
print(l1)
结果>>>[1, 1, 2, 3, 4, 5, 10, 13, 14, 20]
 
原文地址:https://www.cnblogs.com/zwb12345/p/9763260.html