﻿{"id":1473,"date":"2020-06-10T10:26:13","date_gmt":"2020-06-10T02:26:13","guid":{"rendered":"https:\/\/www.tansoo.cn\/?p=1473"},"modified":"2020-06-10T10:26:13","modified_gmt":"2020-06-10T02:26:13","slug":"phpbb-29","status":"publish","type":"post","link":"https:\/\/www.tansoo.cn\/?p=1473","title":{"rendered":"python\u4e2d\u7684lambda\u8868\u8fbe\u5f0f"},"content":{"rendered":"<p><span style=\"font-size:150%;line-height:116%\">lambda\u8868\u8fbe\u5f0f\u662f\u4e00\u884c\u51fd\u6570\u3002<\/span><br \/>\n\u5b83\u4eec\u5728\u5176\u4ed6\u8bed\u8a00\u4e2d\u4e5f\u88ab\u79f0\u4e3a\u533f\u540d\u51fd\u6570\u3002\u5982\u679c\u4f60\u4e0d\u60f3\u5728\u7a0b\u5e8f\u4e2d\u5bf9\u4e00\u4e2a\u51fd\u6570\u4f7f\u7528\u4e24\u6b21\uff0c\u4f60\u4e5f\u8bb8\u4f1a\u60f3\u7528lambda\u8868\u8fbe\u5f0f\uff0c\u5b83\u4eec\u548c\u666e\u901a\u7684\u51fd\u6570\u5b8c\u5168\u4e00\u6837\u3002<\/p>\n<p><strong class=\"text-strong\">\u539f\u578b<\/strong><br \/>\n    lambda \u53c2\u6570:\u64cd\u4f5c(\u53c2\u6570)<br \/>\n\u4f8b\u5b50<\/p>\n<div class=\"codebox_plus_wrap\">\n<div class=\"codebox_plus_header\"><strong>Code: <\/strong><a href=\"#\" onclick=\"codebox_plus_select(this, 1); return false;\">[\u5168\u9009]<\/a>&nbsp;<a href=\"#\" onclick=\"codebox_plus_toggle(this, 1); return false;\">[Expand\/Collapse]<\/a><\/div>\n<div>\n<div style=\"display: inline;\">\n<div class=\"python\" style=\"font-family:monospace;\">\n<ol>\n<li style=\"margin-left:20px;\">\n<div style=\"border-bottom: dotted 1px #cccccc;\">&nbsp; &nbsp; add <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #ff7700;font-weight:bold;\">lambda<\/span> x<span style=\"color: #66cc66;\">,<\/span> y: x + y<\/div>\n<\/li>\n<li style=\"margin-left:20px;\">\n<div style=\"border-bottom: dotted 1px #cccccc;\"><span style=\"color: #808080; font-style: italic;\"># &nbsp;\u540c\u529f\u80fd\u51fd\u6570\u5b9a\u4e49<\/span><\/div>\n<\/li>\n<li style=\"margin-left:20px;\">\n<div style=\"border-bottom: dotted 1px #cccccc;\"><span style=\"color: #808080; font-style: italic;\"># &nbsp; &nbsp;def f(x,y):<\/span><\/div>\n<\/li>\n<li style=\"margin-left:20px;\">\n<div style=\"border-bottom: dotted 1px #cccccc;\"><span style=\"color: #808080; font-style: italic;\"># &nbsp; &nbsp; &nbsp; &nbsp;return x + y<\/span><\/div>\n<\/li>\n<li style=\"margin-left:20px;\">\n<div style=\"border-bottom: dotted 1px #cccccc;\">&nbsp;<\/div>\n<\/li>\n<li style=\"margin-left:20px;\">\n<div style=\"border-bottom: dotted 1px #cccccc;\">&nbsp; &nbsp; <span style=\"color: #ff7700;font-weight:bold;\">print<\/span><span style=\"color: black;\">&#40;<\/span>add<span style=\"color: black;\">&#40;<\/span><span style=\"color: #ff4500;\">3<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #ff4500;\">5<\/span><span style=\"color: black;\">&#41;<\/span><span style=\"color: black;\">&#41;<\/span><\/div>\n<\/li>\n<li style=\"margin-left:20px;\">\n<div style=\"border-bottom: dotted 1px #cccccc;\">&nbsp; &nbsp; <span style=\"color: #808080; font-style: italic;\"># Output: 8<\/span><\/div>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"codebox_plus_footer\">GeSHi &copy; Codebox Plus Extension<\/div>\n<\/div>\n<p>\u8fd9\u8fd8\u6709\u4e00\u4e9blambda\u8868\u8fbe\u5f0f\u7684\u5e94\u7528\u6848\u4f8b\uff0c\u53ef\u4ee5\u5728\u4e00\u4e9b\u7279\u6b8a\u60c5\u51b5\u4e0b\u4f7f\u7528\uff1a<\/p>\n<p>\u5217\u8868\u6392\u5e8f<\/p>\n<div class=\"codebox_plus_wrap\">\n<div class=\"codebox_plus_header\"><strong>Code: <\/strong><a href=\"#\" onclick=\"codebox_plus_select(this, 1); return false;\">[\u5168\u9009]<\/a>&nbsp;<a href=\"#\" onclick=\"codebox_plus_toggle(this, 1); return false;\">[Expand\/Collapse]<\/a><\/div>\n<div>\n<div style=\"display: inline;\">\n<div class=\"python\" style=\"font-family:monospace;\">\n<ol>\n<li style=\"margin-left:20px;\">\n<div style=\"border-bottom: dotted 1px #cccccc;\">&nbsp; &nbsp; a <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: black;\">&#91;<\/span><span style=\"color: black;\">&#40;<\/span><span style=\"color: #ff4500;\">1<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #ff4500;\">2<\/span><span style=\"color: black;\">&#41;<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: black;\">&#40;<\/span><span style=\"color: #ff4500;\">4<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #ff4500;\">1<\/span><span style=\"color: black;\">&#41;<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: black;\">&#40;<\/span><span style=\"color: #ff4500;\">9<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #ff4500;\">10<\/span><span style=\"color: black;\">&#41;<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: black;\">&#40;<\/span><span style=\"color: #ff4500;\">13<\/span><span style=\"color: #66cc66;\">,<\/span> &#8211;<span style=\"color: #ff4500;\">3<\/span><span style=\"color: black;\">&#41;<\/span><span style=\"color: black;\">&#93;<\/span><\/div>\n<\/li>\n<li style=\"margin-left:20px;\">\n<div style=\"border-bottom: dotted 1px #cccccc;\">&nbsp; &nbsp; a.<span style=\"color: black;\">sort<\/span><span style=\"color: black;\">&#40;<\/span>key<span style=\"color: #66cc66;\">=<\/span><span style=\"color: #ff7700;font-weight:bold;\">lambda<\/span> x: x<span style=\"color: black;\">&#91;<\/span><span style=\"color: #ff4500;\">1<\/span><span style=\"color: black;\">&#93;<\/span><span style=\"color: black;\">&#41;<\/span><\/div>\n<\/li>\n<li style=\"margin-left:20px;\">\n<div style=\"border-bottom: dotted 1px #cccccc;\">&nbsp;<\/div>\n<\/li>\n<li style=\"margin-left:20px;\">\n<div style=\"border-bottom: dotted 1px #cccccc;\">&nbsp; &nbsp; <span style=\"color: #ff7700;font-weight:bold;\">print<\/span><span style=\"color: black;\">&#40;<\/span>a<span style=\"color: black;\">&#41;<\/span><\/div>\n<\/li>\n<li style=\"margin-left:20px;\">\n<div style=\"border-bottom: dotted 1px #cccccc;\">&nbsp; &nbsp; <span style=\"color: #808080; font-style: italic;\"># Output: [(13, -3), (4, 1), (1, 2), (9, 10)]<\/span><\/div>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"codebox_plus_footer\">GeSHi &copy; Codebox Plus Extension<\/div>\n<\/div>\n<p>\u5217\u8868\u5e76\u884c\u6392\u5e8f<\/p>\n<div class=\"codebox_plus_wrap\">\n<div class=\"codebox_plus_header\"><strong>Code: <\/strong><a href=\"#\" onclick=\"codebox_plus_select(this, 1); return false;\">[\u5168\u9009]<\/a>&nbsp;<a href=\"#\" onclick=\"codebox_plus_toggle(this, 1); return false;\">[Expand\/Collapse]<\/a><\/div>\n<div>\n<div style=\"display: inline;\">\n<div class=\"python\" style=\"font-family:monospace;\">\n<ol>\n<li style=\"margin-left:20px;\">\n<div style=\"border-bottom: dotted 1px #cccccc;\">&nbsp; &nbsp; data <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #008000;\">zip<\/span><span style=\"color: black;\">&#40;<\/span>list1<span style=\"color: #66cc66;\">,<\/span> list2<span style=\"color: black;\">&#41;<\/span><\/div>\n<\/li>\n<li style=\"margin-left:20px;\">\n<div style=\"border-bottom: dotted 1px #cccccc;\">&nbsp; &nbsp; data.<span style=\"color: black;\">sort<\/span><span style=\"color: black;\">&#40;<\/span><span style=\"color: black;\">&#41;<\/span><\/div>\n<\/li>\n<li style=\"margin-left:20px;\">\n<div style=\"border-bottom: dotted 1px #cccccc;\">&nbsp; &nbsp; list1<span style=\"color: #66cc66;\">,<\/span> list2 <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #008000;\">map<\/span><span style=\"color: black;\">&#40;<\/span><span style=\"color: #ff7700;font-weight:bold;\">lambda<\/span> t: <span style=\"color: #008000;\">list<\/span><span style=\"color: black;\">&#40;<\/span>t<span style=\"color: black;\">&#41;<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #008000;\">zip<\/span><span style=\"color: black;\">&#40;<\/span>*data<span style=\"color: black;\">&#41;<\/span><span style=\"color: black;\">&#41;<\/span><\/div>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"codebox_plus_footer\">GeSHi &copy; Codebox Plus Extension<\/div>\n<\/div>\n<p><small>\u539f\u6587\u4f5c\u8005: BG6RSH | <a href=\"https:\/\/bbs.tansoo.cn\/viewtopic.php?t=29\" target=\"_blank\" rel=\"noopener\">\u67e5\u770b\u539f\u5e16<\/a><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>lambda\u8868\u8fbe\u5f0f\u662f\u4e00\u884c\u51fd\u6570\u3002 \u5b83\u4eec\u5728\u5176\u4ed6\u8bed\u8a00\u4e2d\u4e5f\u88ab\u79f0\u4e3a\u533f\u540d\u51fd\u6570\u3002\u5982\u679c\u4f60\u4e0d\u60f3\u5728\u7a0b &hellip; <a href=\"https:\/\/www.tansoo.cn\/?p=1473\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105],"tags":[],"class_list":["post-1473","post","type-post","status-publish","format-standard","hentry","category-105"],"_links":{"self":[{"href":"https:\/\/www.tansoo.cn\/index.php?rest_route=\/wp\/v2\/posts\/1473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tansoo.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tansoo.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tansoo.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tansoo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1473"}],"version-history":[{"count":0,"href":"https:\/\/www.tansoo.cn\/index.php?rest_route=\/wp\/v2\/posts\/1473\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tansoo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tansoo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tansoo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}