{"id":2516,"date":"2022-08-11T10:48:06","date_gmt":"2022-08-11T02:48:06","guid":{"rendered":"http:\/\/cnliutz.uicp.io\/?p=2516"},"modified":"2022-08-11T10:48:06","modified_gmt":"2022-08-11T02:48:06","slug":"%e5%9f%ba%e6%9c%ac%e5%87%bd%e6%95%b0input-print-map-filter-reduce%e5%92%8clambda%e7%ae%97%e5%ad%90-operater%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"http:\/\/g1n29wqq.ipyingshe.net:5347\/?p=2516","title":{"rendered":"\u57fa\u672c\u51fd\u6570input() print() map() filter() reduce()\u548clambda()\u7b97\u5b50-operater\u7528\u6cd5"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>#\u8f93\u5165\u9017\u53f7\u5206\u5272\u7684\u4e24\u4e2a\u6570\u5b57--input\u8f93\u5165\u7684\u5185\u5bb9\uff0c\u9ed8\u8ba4\u4e3a\u5b57\u7b26\u7c7b\u578b\nx,y =input(\"input:\").split(\",\")\nprint(x,y)\n\n#\u8f93\u5165\u7684\u591a\u4e2a\u6570\u636e\u8f6c\u6362\u6210\u6570\u503c\u5217\u8868\n# lst = list(eval(input(\"\u8f93\u5165\u6570\u636e\uff0c\u8f6c\u5316\u6210\u6570\u503c\uff1a\")))\n\nlst = &#91;\"3\",\"6\",\"7\",\"2\",\"4\"]\nlsts = list(eval(item) for item in lst)\nprint(lsts)\n#print\uff08\"your string here.\",sep=\",\",end=\"\"\uff09\u8f93\u51fa\u7684\u884c\u5c3e\u9ed8\u8ba4\u8ddf\u4e00\u4e2a\u6362\u884c\u7b26\uff08\\n\uff09--\u53ef\u6307\u5b9a\u7a7a\u683c--\u4e00\u884c\u8f93\u51fa\u4e0d\u6362\u884c\u3002sep\u6307\u5b9a\u8f93\u51fa\u5185\u5bb9\u5206\u9694\u7b26\uff1a\u5982\u9017\u53f7\u3002\nfor i in range(10):\n    print(i)\n\nfor i in range(10):\n    print(i,end=\" \")\nprint()\n\nchars =\"0123\"\nbb= \"456789\"\ncc = \"123abc\"\nprint(chars,bb,cc,sep=\",\")\nprint()\n    \n#\u57fa\u672c\u51fd\u6570 map() filter() reduce()\u548clambda()\u7b97\u5b50-operater\n\n#using map()\nlst=&#91;7,4,8,3,2,9]\nx = list(map(lambda x:x**2,lst))  #\u5bf9\u5217\u8868\u6bcf\u4e00\u4e2a\u5bf9\u8c61\u5e94\u7528lambda\u51fd\u6570\u60ca\u9192\u8ba1\u7b97\nprint(x)\n#\u5b57\u6bcd\u53d8\u5927\u5199\nlst = &#91;\"huawei\",\"apple\"]\n#lst1 = map(upper,lst) #error when running\nlst1 = map(lambda word : word.upper() ,lst)\n#print(lst1) can not get the result\nfor i in lst1:\n    print(i,end =\" \")\nprint()\n\n#using filter()\nlst = &#91;2,3,4,5,6,7,8,9]\ny = list(filter(lambda x:x%2==0,lst))\nprint(y)\nprint()\n\n#using reduce()\nfrom functools import reduce\nlst=&#91;1,2,3,4,5]\nlst3 = reduce(lambda x,y:x+y,lst) #\u9012\u5f52\u8ba1\u7b97\n'''\n1:x+y  1+2=3\n2:x+y  3+3=6\n3:x+y  6+4=10\n4:x+y  10+5=15\n'''\nprint(lst3)\n#output:15\nprint(\"\u5408\u8ba1\uff1a\",sum(lst))  #\u53c2\u7167reduce()<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,10],"tags":[],"class_list":["post-2516","post","type-post","status-publish","format-standard","hentry","category-2","category-python"],"_links":{"self":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/2516","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2516"}],"version-history":[{"count":0,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/2516\/revisions"}],"wp:attachment":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2516"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}