{"id":173831,"date":"2023-07-31T01:03:55","date_gmt":"2023-07-30T17:03:55","guid":{"rendered":"http:\/\/www.idc.net\/help\/173831\/"},"modified":"2023-07-31T01:03:55","modified_gmt":"2023-07-30T17:03:55","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91python%e6%95%99%e7%a8%8b%ef%bc%9apython%e9%ab%98%e7%ba%a7%e5%87%bd%e6%95%b0%e6%9c%89%e5%87%a0%e4%b8%aa%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/173831\/","title":{"rendered":"\u540e\u6d6a\u4e91Python\u6559\u7a0b\uff1apython\u9ad8\u7ea7\u51fd\u6570\u6709\u51e0\u4e2a\uff1f"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/oss.py.cn\/pycn\/upload\/image\/742\/451\/286\/1613618047884128.png\" class=\"aligncenter\"><\/p>\n<p><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1;font-size:14px\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1\">\u672c\u6587\u6559\u7a0b\u64cd\u4f5c\u73af\u5883\uff1a<\/span>windows7\u7cfb\u7edf\u3001Python 3.9.1\uff0cDELL G3\u7535\u8111\u3002<\/span><\/p>\n<p><strong>1\u3001filter<\/strong><\/p>\n<p>\u7528\u4e8e\u7b5b\u9009\u6570\u636e\uff0c\u53ea\u4fdd\u7559\u6ee1\u8db3\u6761\u4ef6\u7684\u503c filter(function, iterable)<\/p>\n<p>\u4e24\u4e2a\u53c2\u6570\uff1a\u7b2c\u4e00\u4e2a\u662f\u51fd\u6570\uff0c\u7b2c\u4e8c\u4e2a\u662f\u8fed\u4ee3\u6570\u636e\u3002<\/p>\n<pre>#&nbsp;\u7b5b\u9009100\u4ee5\u5185\u4e2a\u4f4d\u6570\u4e3a1\u7684\u5143\u7d20\u3002\nlist(filter(lambdax:&nbsp;x&nbsp;%&nbsp;10&nbsp;==&nbsp;1,&nbsp;range(100)))\n(Output:[1,&nbsp;11,&nbsp;21,&nbsp;31,&nbsp;41,&nbsp;51,&nbsp;61,&nbsp;71,&nbsp;81,&nbsp;91])<\/pre>\n<p><strong>2\u3001map<\/strong><\/p>\n<p>\u5bf9\u6570\u636e\u6240\u6709\u5143\u7d20\u6267\u884c\u540c\u4e00\u64cd\u4f5c\u3002<\/p>\n<pre>map(function,&nbsp;iterable)<\/pre>\n<p><strong>3\u3001reduce<\/strong><\/p>\n<p>\u5bf9\u6570\u636e\u7684\u6240\u6709\u5143\u7d20\u4f9d\u6b21\u7d2f\u79ef\u8fdb\u884c\u8ba1\u7b97\uff0c\u9996\u5148\u8ba1\u7b97\u524d\u4e24\u4e2a\u5143\u7d20\u7684\u51fd\u6570\u7ed3\u679c\uff0c\u518d\u8ba1\u7b97\u8be5\u7ed3\u679c\u548c\u7b2c\u4e09\u4e2a\u5143\u7d20\u7684\u51fd\u6570\u7ed3\u679c\uff0c\u4f9d\u6b21\u7c7b\u63a8\u3002<\/p>\n<pre>reduce(function,&nbsp;iterable[,&nbsp;initializer])<\/pre>\n<p><strong>4\u3001sorted<\/strong><\/p>\n<p>\u5bf9\u6570\u636e\u6392\u5e8f\u3002<\/p>\n<pre>sorted(iterable,&nbsp;key=None,&nbsp;reverse=False)<\/pre>\n<p>\u601d\u8003\uff1a\u5982\u4f55\u8ba1\u7b975\u4ee5\u5185\u7684\u6570\u7684\u5e73\u65b9\u548c\uff1f\u5bf95\u4ee5\u5185\u7684\u6b63\u6570x\u8ba1\u7b97(x-2) ** 2\uff0c\u5e76\u9006\u5e8f\u6392\u5e8f\u3002<\/p>\n<pre>reduce(lambda&nbsp;x,y:&nbsp;x+y,&nbsp;map(lambdax:&nbsp;x&nbsp;*&nbsp;x,&nbsp;range(5)))\n(Output:30)\nsorted(map(lambdax:&nbsp;(x-2)&nbsp;**&nbsp;2,&nbsp;range(1,&nbsp;5)),&nbsp;reverse=True)\n(Output:[4,&nbsp;1,&nbsp;1,&nbsp;0])<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662fpython\u4e2d\u76844\u79cd\u9ad8\u7ea7\u51fd\u6570\uff0c\u5927\u5bb6\u5b66\u5b8c\u540e\u4f1a\u53d1\u73b0\u5176\u5b9e\u5c31\u662f\u6211\u4eec\u5e38\u89c1\u7684\u57fa\u7840\u51fd\u6570\uff0c\u4e0d\u8fc7\u5728\u4e00\u4e9b\u7279\u6b8a\u7684\u7528\u6cd5\u4e0a\u5c5e\u4e8e\u9ad8\u7ea7\u7684\u8303\u7574\uff0c\u5b66\u4f1a\u540e\u4e5f\u8d76\u5feb\u5c55\u5f00\u7ec3\u4e60\u5427\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u6559\u7a0b\u64cd\u4f5c\u73af\u5883\uff1awindows7\u7cfb\u7edf\u3001Python 3.9.1\uff0cDELL G3\u7535\u8111\u3002 1\u3001filter \u7528\u4e8e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":173832,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182397],"tags":[],"class_list":["post-173831","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/173831","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=173831"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/173831\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/173832"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=173831"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=173831"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=173831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}