\u5f88\u591a\u8bed\u8a00\u90fd\u6709\u533f\u540d\u51fd\u6570\uff0cpython\u7684\u533f\u540d\u51fd\u6570\u5199\u4f5clambda\uff0c\u5f53\u9700\u8981\u5b9e\u73b0\u4e00\u5b9a\u529f\u80fd\u800c\u53c8\u4e0d\u60f3\u201c\u5927\u5f20\u65d7\u9f13\u201d\u7684def\u4e00\u4e2a\u51fd\u6570\u65f6\uff0clambda\u5c31\u662f\u6700\u4f18\u7684\u9009\u62e9\u3002<\/p>\n
lambda x:x**2 \r\n# (x)> \r\n<\/pre>\n\u4e5f\u53ef\u4ee5\u5c06\u5b83\u8d4b\u503c\u7ed9\u4e00\u4e2a\u53d8\u91cf\uff0c\u7531\u4e8epython\u4e2d\u4e00\u5207\u7686\u5bf9\u8c61\uff0c\u6240\u4ee5\u540e\u7eed\u7a0b\u5e8f\u4e2d\u5c31\u53ef\u4ee5\u7528\u8be5\u53d8\u91cf\u8c03\u7528\u8fd9\u4e2a\u533f\u540d\u51fd\u6570\u3002<\/p>\n
f = lambda x:x**2 \r\nf(2) \r\n# 4 \r\n<\/pre>\n\u5f53\u7136\uff0c\u8fd9\u91cc\u5176\u5b9e\u6ca1\u5fc5\u8981\u5e94\u7528lambda\u6765\u5b9e\u73b0\uff0c\u56e0\u4e3a\u65e2\u7136\u8981\u663e\u5f0f\u8c03\u7528\uff0c\u8fd8\u4e0d\u5982\u5e72\u8106\u76f4\u63a5\u5199\u4e2a\u660e\u786e\u7684\u51fd\u6570\u7f62\u4e86\u3002lambda\u51fd\u6570\u66f4\u5e7f\u6cdb\u7684\u5e94\u7528\u573a\u666f\u5728\u4e8e\u8be5\u533f\u540d\u51fd\u6570\u4f5c\u4e3a\u53e6\u4e00\u4e2a\u51fd\u6570\u7684\u53c2\u6570\u4f20\u9012\u65f6\uff0c\u5e94\u7528\u5c31\u6bd4\u8f83\u5408\u9002\u4e86\uff0c\u4f8b\u5982\uff0c\u5c06lambda\u4f5c\u4e3asort()\u51fd\u6570\u7684key\u53c2\u6570\uff0c\u5c31\u53ef\u4ee5\u5b9e\u73b0\u7279\u5b9a\u529f\u80fd\u7684\u6392\u5e8f\u3002<\/p>\n
dyct = {'a':2, 'b':1, 'c':5} \r\nsorted(dyct.items(), key = lambda x:x[1]) \r\n# [('b', 1), ('a', 2), ('c', 5)] \r\n<\/pre>\n02 \u667a\u80fd\u89e3\u538b\uff1azip<\/strong><\/div>\nzip\u51fd\u6570\u4eba\u5982\u5176\u540d\uff0c\u662f\u6253\u5305\u6216\u8005\u89e3\u5305\u7684\u51fd\u6570\uff0c\u63a5\u53d72\u4e2a\u4ee5\u4e0a\u53ef\u8fed\u4ee3\u53d8\u91cf\uff0c\u8f93\u51fa\u5bf9\u5e94\u4f4d\u7f6e\u7ec4\u6210\u5143\u7ec4\u540e\u7684\u8fed\u4ee3\u7c7b\u578b\u3002\u4f8b\u5982\uff1a<\/p>\n
a = ['a', 'b', 'c'] \r\nb = (4, 5, 6) \r\nzip(a,b) \r\n# \r\nlist(zip(a,b)) \r\n# [('a', 4), ('b', 5), ('c', 6)] \r\ntuple(zip(a,b)) \r\n# (('a', 4), ('b', 5), ('c', 6)) \r\n<\/pre>\n\u4e5f\u53ef\u4ee5\u63a5\u53d7\u591a\u4e8e2\u4e2a\u8f93\u5165\u53ef\u8fed\u4ee3\u53d8\u91cf\uff0c\u800c\u4e14\u5982\u679c\u5404\u8fed\u4ee3\u53d8\u91cf\u957f\u5ea6\u4e0d\u4e00\u81f4\u4e5f\u4e0d\u4f1a\u62a5\u9519\uff0c\u53ea\u662f\u6b64\u65f6\u8fd4\u56de\u8fed\u4ee3\u53d8\u91cf\u53d6\u51b3\u4e8e\u8f93\u5165\u603b\u957f\u5ea6\u6700\u77ed\u7684\u4e00\u4e2a\u3002\u4f8b\u5982\uff1a<\/p>\n
a = ['a', 'b', 'c', 'd', 'e'] \r\nb = (4, 5, 6, 7) \r\nc = [True, False, True] \r\nlist(zip(a,b,c)) \r\n# (('a', 4, True), ('b', 5, False), ('c', 6, True)) \r\n<\/pre>\n\u4e0ezip\u6253\u5305\u76f8\u5bf9\u5e94\u7684\u7528\u6cd5\u662f\u89e3\u5305\uff0c\u5373\u5bf9\u4e00\u4e2a\u6253\u5305\u5f62\u5f0f\u7684\u5143\u7d20\u8fdb\u884c\u4f9d\u6b21\u89e3\u5305\uff0c\u5e76\u8fd4\u56de\u591a\u4e2a\u65b0\u7684\u5217\u8868\u3002\u4f8b\u5982\uff1a<\/p>\n
aZip = (('a', 4, True), ('b', 5, False), ('c', 6, True)) \r\na, b, c = zip(*aZip) \r\n# a:('a', 'b', 'c') \r\n# b:(4, 5, 6) \r\n# c:(True, False, True) \r\n<\/pre>\n03 \u4e00\u4e00\u6620\u5c04\uff1amap<\/strong><\/div>\nmap\u51fd\u6570\u4e5f\u6b63\u5982\u5176\u53d6\u540d\u4e00\u6837\uff0c\u662f\u4e00\u4e2a\u5c06\u63a5\u53d7\u7684\u8fed\u4ee3\u53d8\u91cf\u4f9d\u6b21\u7ecf\u8fc7\u67d0\u79cd\u6620\u5c04\uff0c\u5e76\u8f93\u51fa\u6620\u5c04\u540e\u7684\u8fed\u4ee3\u53d8\u91cf\u3002\u4f8b\u5982\uff0c\u5982\u679c\u5bf9\u5217\u8868\u4e2d\u7684\u67d0\u4e2a\u53d8\u91cf\u4f9d\u6b21\u5b8c\u6210\u6c42\u503c\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u5217\u8868\uff0c\u5219\u53ef\u4ee5\u5e94\u7528map\uff1a<\/p>\n
a = [1, 2, 3, 4] \r\nmap(str, a) \r\n# \r\n\r\n\r\n