{"id":1053151,"date":"2024-12-31T14:31:21","date_gmt":"2024-12-31T06:31:21","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1053151.html"},"modified":"2024-12-31T14:31:24","modified_gmt":"2024-12-31T06:31:24","slug":"python%e5%a6%82%e4%bd%95%e7%ad%9b%e9%80%89%e5%87%ba%e7%ac%a6%e5%90%88%e6%9d%a1%e4%bb%b6%e7%9a%84%e5%90%8d%e5%ad%97","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1053151.html","title":{"rendered":"python\u5982\u4f55\u7b5b\u9009\u51fa\u7b26\u5408\u6761\u4ef6\u7684\u540d\u5b57"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/658afd09-9eed-4947-a2df-6705ef7b207e.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python\u5982\u4f55\u7b5b\u9009\u51fa\u7b26\u5408\u6761\u4ef6\u7684\u540d\u5b57\" \/><\/p>\n<p><p> <strong>\u8981\u5728Python\u4e2d\u7b5b\u9009\u51fa\u7b26\u5408\u6761\u4ef6\u7684\u540d\u5b57\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\uff0c\u4f8b\u5982\u5217\u8868\u89e3\u6790\u3001filter\u51fd\u6570\u548c\u6b63\u5219\u8868\u8fbe\u5f0f\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u4f18\u70b9\u548c\u9002\u7528\u573a\u666f\uff0c\u4f8b\u5982\uff0c\u5217\u8868\u89e3\u6790\u9002\u7528\u4e8e\u7b80\u5355\u6761\u4ef6\u7b5b\u9009\u3001filter\u51fd\u6570\u9002\u7528\u4e8e\u590d\u6742\u6761\u4ef6\u7b5b\u9009\u3001\u6b63\u5219\u8868\u8fbe\u5f0f\u9002\u7528\u4e8e\u6a21\u5f0f\u5339\u914d\u3002<\/strong> \u5176\u4e2d\uff0c\u5217\u8868\u89e3\u6790\u662f\u6700\u5e38\u7528\u548c\u6700\u7b80\u6d01\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002\u4e0b\u9762\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e09\u79cd\u65b9\u6cd5\uff0c\u5e76\u63d0\u4f9b\u4ee3\u7801\u793a\u4f8b\uff0c\u4ee5\u4fbf\u60a8\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u66f4\u597d\u5730\u9009\u62e9\u9002\u5408\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5217\u8868\u89e3\u6790<\/h3>\n<\/p>\n<p><p>\u5217\u8868\u89e3\u6790\u662f\u4e00\u79cd\u7b80\u6d01\u4e14\u9ad8\u6548\u7684\u65b9\u6cd5\uff0c\u7528\u4e8e\u4ece\u5217\u8868\u4e2d\u7b5b\u9009\u51fa\u7b26\u5408\u6761\u4ef6\u7684\u5143\u7d20\u3002\u5b83\u7684\u8bed\u6cd5\u7b80\u5355\uff0c\u6613\u4e8e\u7406\u89e3\u548c\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">names = [&quot;Alice&quot;, &quot;Bob&quot;, &quot;Charlie&quot;, &quot;David&quot;, &quot;Eve&quot;]<\/p>\n<p>filtered_names = [name for name in names if len(name) &gt; 3]<\/p>\n<p>print(filtered_names)  # \u8f93\u51fa: [&#39;Alice&#39;, &#39;Charlie&#39;, &#39;David&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u5217\u8868\u89e3\u6790\u7b5b\u9009\u51fa\u540d\u5b57\u957f\u5ea6\u5927\u4e8e3\u7684\u540d\u5b57\u3002<strong>\u5217\u8868\u89e3\u6790\u7684\u8bed\u6cd5\u4e3a <code>[expression for item in iterable if condition]<\/code>\uff0c\u5176\u4e2d<code>expression<\/code>\u662f\u9700\u8981\u8ba1\u7b97\u7684\u8868\u8fbe\u5f0f\uff0c<code>item<\/code>\u662f\u8fed\u4ee3\u7684\u5143\u7d20\uff0c<code>iterable<\/code>\u662f\u53ef\u8fed\u4ee3\u5bf9\u8c61\uff0c<code>condition<\/code>\u662f\u7b5b\u9009\u6761\u4ef6<\/strong>\u3002<\/p>\n<\/p>\n<p><h4>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/h4>\n<\/p>\n<p><p>\u5217\u8868\u89e3\u6790\u4e0d\u4ec5\u7b80\u6d01\uff0c\u800c\u4e14\u6267\u884c\u6548\u7387\u9ad8\u3002\u5b83\u5728Python\u5185\u90e8\u8fdb\u884c\u4e86\u4f18\u5316\uff0c\u901a\u5e38\u6bd4\u4f7f\u7528\u663e\u5f0ffor\u5faa\u73af\u66f4\u5feb\u3002\u5bf9\u4e8e\u7b80\u5355\u6761\u4ef6\u7b5b\u9009\uff0c\u63a8\u8350\u4f7f\u7528\u5217\u8868\u89e3\u6790\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001filter\u51fd\u6570<\/h3>\n<\/p>\n<p><p>filter\u51fd\u6570\u7528\u4e8e\u6839\u636e\u6307\u5b9a\u6761\u4ef6\u7b5b\u9009\u53ef\u8fed\u4ee3\u5bf9\u8c61\u4e2d\u7684\u5143\u7d20\u3002\u5b83\u8fd4\u56de\u4e00\u4e2afilter\u5bf9\u8c61\uff0c\u9700\u8981\u5c06\u5176\u8f6c\u6362\u4e3a\u5217\u8868\u6216\u5176\u4ed6\u53ef\u8fed\u4ee3\u7c7b\u578b\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">names = [&quot;Alice&quot;, &quot;Bob&quot;, &quot;Charlie&quot;, &quot;David&quot;, &quot;Eve&quot;]<\/p>\n<p>def condition(name):<\/p>\n<p>    return len(name) &gt; 3<\/p>\n<p>filtered_names = list(filter(condition, names))<\/p>\n<p>print(filtered_names)  # \u8f93\u51fa: [&#39;Alice&#39;, &#39;Charlie&#39;, &#39;David&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u6761\u4ef6\u51fd\u6570<code>condition<\/code>\uff0c\u5e76\u4f7f\u7528filter\u51fd\u6570\u7b5b\u9009\u51fa\u540d\u5b57\u957f\u5ea6\u5927\u4e8e3\u7684\u540d\u5b57\u3002<strong>filter\u51fd\u6570\u7684\u8bed\u6cd5\u4e3a<code>filter(function, iterable)<\/code>\uff0c\u5176\u4e2d<code>function<\/code>\u662f\u7528\u4e8e\u7b5b\u9009\u6761\u4ef6\u7684\u51fd\u6570\uff0c<code>iterable<\/code>\u662f\u53ef\u8fed\u4ee3\u5bf9\u8c61<\/strong>\u3002<\/p>\n<\/p>\n<p><h4>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/h4>\n<\/p>\n<p><p>filter\u51fd\u6570\u9002\u7528\u4e8e\u590d\u6742\u6761\u4ef6\u7b5b\u9009\uff0c\u5c24\u5176\u662f\u5f53\u6761\u4ef6\u903b\u8f91\u8f83\u4e3a\u590d\u6742\u65f6\uff0c\u5c06\u6761\u4ef6\u903b\u8f91\u5c01\u88c5\u5728\u51fd\u6570\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u4ee3\u7801\u66f4\u6e05\u6670\u548c\u6613\u4e8e\u7ef4\u62a4\u3002\u4f7f\u7528filter\u51fd\u6570\u65f6\uff0c\u6761\u4ef6\u51fd\u6570\u8fd4\u56de\u503c\u4e3aTrue\u7684\u5143\u7d20\u5c06\u88ab\u4fdd\u7559\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u6b63\u5219\u8868\u8fbe\u5f0f<\/h3>\n<\/p>\n<p><p>\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u4e00\u79cd\u5f3a\u5927\u7684\u5b57\u7b26\u4e32\u6a21\u5f0f\u5339\u914d\u5de5\u5177\uff0c\u9002\u7528\u4e8e\u6839\u636e\u590d\u6742\u6a21\u5f0f\u7b5b\u9009\u5b57\u7b26\u4e32\u3002Python\u7684<code>re<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u5904\u7406\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<p>names = [&quot;Alice&quot;, &quot;Bob&quot;, &quot;Charlie&quot;, &quot;David&quot;, &quot;Eve&quot;]<\/p>\n<p>pattern = re.compile(r&#39;^[A-D].*&#39;)<\/p>\n<p>filtered_names = [name for name in names if pattern.match(name)]<\/p>\n<p>print(filtered_names)  # \u8f93\u51fa: [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Charlie&#39;, &#39;David&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u7b5b\u9009\u51fa\u4ee5\u5b57\u6bcdA\u5230D\u5f00\u5934\u7684\u540d\u5b57\u3002<strong>\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u8bed\u6cd5\u4e3a<code>re.compile(pattern)<\/code>\uff0c\u5176\u4e2d<code>pattern<\/code>\u662f\u8981\u5339\u914d\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u6a21\u5f0f<\/strong>\u3002<\/p>\n<\/p>\n<p><h4>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/h4>\n<\/p>\n<p><p>\u6b63\u5219\u8868\u8fbe\u5f0f\u9002\u7528\u4e8e\u6839\u636e\u590d\u6742\u6a21\u5f0f\u7b5b\u9009\u5b57\u7b26\u4e32\u3002\u5b83\u652f\u6301\u591a\u79cd\u5339\u914d\u89c4\u5219\u548c\u6a21\u5f0f\uff0c\u80fd\u591f\u5904\u7406\u5927\u591a\u6570\u5b57\u7b26\u4e32\u5339\u914d\u95ee\u9898\u3002\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u7f16\u5199\u6b63\u786e\u7684\u5339\u914d\u6a21\u5f0f\uff0c\u5e76\u786e\u4fdd\u5176\u80fd\u591f\u6b63\u786e\u5904\u7406\u6240\u6709\u53ef\u80fd\u7684\u8f93\u5165\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u7efc\u5408\u793a\u4f8b<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u7ed3\u5408\u591a\u79cd\u65b9\u6cd5\u8fdb\u884c\u7b5b\u9009\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7efc\u5408\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u7ed3\u5408\u5217\u8868\u89e3\u6790\u3001filter\u51fd\u6570\u548c\u6b63\u5219\u8868\u8fbe\u5f0f\u8fdb\u884c\u7b5b\u9009\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<p>names = [&quot;Alice&quot;, &quot;Bob&quot;, &quot;Charlie&quot;, &quot;David&quot;, &quot;Eve&quot;, &quot;Frank&quot;, &quot;Grace&quot;, &quot;Hannah&quot;]<\/p>\n<h2><strong>\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u7b5b\u9009\u51fa\u4ee5\u5b57\u6bcdA\u5230D\u5f00\u5934\u7684\u540d\u5b57<\/strong><\/h2>\n<p>pattern = re.compile(r&#39;^[A-D].*&#39;)<\/p>\n<p>filtered_names_regex = [name for name in names if pattern.match(name)]<\/p>\n<h2><strong>\u4f7f\u7528filter\u51fd\u6570\u7b5b\u9009\u51fa\u540d\u5b57\u957f\u5ea6\u5927\u4e8e3\u7684\u540d\u5b57<\/strong><\/h2>\n<p>def condition(name):<\/p>\n<p>    return len(name) &gt; 3<\/p>\n<p>filtered_names_length = list(filter(condition, filtered_names_regex))<\/p>\n<p>print(filtered_names_length)  # \u8f93\u51fa: [&#39;Alice&#39;, &#39;Charlie&#39;, &#39;David&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u7b5b\u9009\u51fa\u4ee5\u5b57\u6bcdA\u5230D\u5f00\u5934\u7684\u540d\u5b57\uff0c\u7136\u540e\u4f7f\u7528filter\u51fd\u6570\u8fdb\u4e00\u6b65\u7b5b\u9009\u51fa\u540d\u5b57\u957f\u5ea6\u5927\u4e8e3\u7684\u540d\u5b57\u3002<strong>\u7ed3\u5408\u591a\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u66f4\u52a0\u590d\u6742\u7684\u7b5b\u9009\u903b\u8f91\uff0c\u6ee1\u8db3\u5b9e\u9645\u5e94\u7528\u4e2d\u7684\u591a\u79cd\u9700\u6c42<\/strong>\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u6027\u80fd\u6bd4\u8f83<\/h3>\n<\/p>\n<p><p>\u5728\u9009\u62e9\u7b5b\u9009\u65b9\u6cd5\u65f6\uff0c\u6027\u80fd\u4e5f\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u8003\u8651\u56e0\u7d20\u3002\u5217\u8868\u89e3\u6790\u901a\u5e38\u6bd4filter\u51fd\u6570\u548c\u6b63\u5219\u8868\u8fbe\u5f0f\u66f4\u5feb\uff0c\u5c24\u5176\u662f\u5728\u7b80\u5355\u6761\u4ef6\u7b5b\u9009\u65f6\u3002\u7136\u800c\uff0c\u5bf9\u4e8e\u590d\u6742\u6761\u4ef6\u7b5b\u9009\uff0cfilter\u51fd\u6570\u548c\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u80fd\u66f4\u5177\u4f18\u52bf\u3002<\/p>\n<\/p>\n<p><h4>\u6027\u80fd\u6d4b\u8bd5\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import time<\/p>\n<p>names = [&quot;Alice&quot;, &quot;Bob&quot;, &quot;Charlie&quot;, &quot;David&quot;, &quot;Eve&quot;, &quot;Frank&quot;, &quot;Grace&quot;, &quot;Hannah&quot;] * 100000<\/p>\n<h2><strong>\u5217\u8868\u89e3\u6790<\/strong><\/h2>\n<p>start_time = time.time()<\/p>\n<p>filtered_names_list_comp = [name for name in names if len(name) &gt; 3]<\/p>\n<p>end_time = time.time()<\/p>\n<p>print(f&quot;\u5217\u8868\u89e3\u6790\u65f6\u95f4: {end_time - start_time} \u79d2&quot;)<\/p>\n<h2><strong>filter\u51fd\u6570<\/strong><\/h2>\n<p>start_time = time.time()<\/p>\n<p>filtered_names_filter = list(filter(lambda name: len(name) &gt; 3, names))<\/p>\n<p>end_time = time.time()<\/p>\n<p>print(f&quot;filter\u51fd\u6570\u65f6\u95f4: {end_time - start_time} \u79d2&quot;)<\/p>\n<h2><strong>\u6b63\u5219\u8868\u8fbe\u5f0f<\/strong><\/h2>\n<p>pattern = re.compile(r&#39;.{4,}&#39;)<\/p>\n<p>start_time = time.time()<\/p>\n<p>filtered_names_regex = [name for name in names if pattern.match(name)]<\/p>\n<p>end_time = time.time()<\/p>\n<p>print(f&quot;\u6b63\u5219\u8868\u8fbe\u5f0f\u65f6\u95f4: {end_time - start_time} \u79d2&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5bf9\u5217\u8868\u89e3\u6790\u3001filter\u51fd\u6570\u548c\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u6027\u80fd\u8fdb\u884c\u4e86\u6d4b\u8bd5\u3002<strong>\u5217\u8868\u89e3\u6790\u901a\u5e38\u5728\u7b80\u5355\u6761\u4ef6\u7b5b\u9009\u65f6\u6027\u80fd\u6700\u4f73\uff0c\u800cfilter\u51fd\u6570\u548c\u6b63\u5219\u8868\u8fbe\u5f0f\u5728\u590d\u6742\u6761\u4ef6\u7b5b\u9009\u65f6\u53ef\u80fd\u66f4\u5177\u4f18\u52bf<\/strong>\u3002<\/p>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u7b5b\u9009\u7b26\u5408\u6761\u4ef6\u7684\u540d\u5b57\u662fPython\u7f16\u7a0b\u4e2d\u7684\u5e38\u89c1\u4efb\u52a1\u3002<strong>\u5217\u8868\u89e3\u6790\u9002\u7528\u4e8e\u7b80\u5355\u6761\u4ef6\u7b5b\u9009\uff0c\u8bed\u6cd5\u7b80\u6d01\uff0c\u6267\u884c\u6548\u7387\u9ad8<\/strong>\uff1b<strong>filter\u51fd\u6570\u9002\u7528\u4e8e\u590d\u6742\u6761\u4ef6\u7b5b\u9009\uff0c\u5c06\u6761\u4ef6\u903b\u8f91\u5c01\u88c5\u5728\u51fd\u6570\u4e2d\uff0c\u4f7f\u4ee3\u7801\u66f4\u6e05\u6670\u548c\u6613\u4e8e\u7ef4\u62a4<\/strong>\uff1b<strong>\u6b63\u5219\u8868\u8fbe\u5f0f\u9002\u7528\u4e8e\u6839\u636e\u590d\u6742\u6a21\u5f0f\u7b5b\u9009\u5b57\u7b26\u4e32\uff0c\u652f\u6301\u591a\u79cd\u5339\u914d\u89c4\u5219\u548c\u6a21\u5f0f<\/strong>\u3002\u7ed3\u5408\u591a\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u66f4\u52a0\u590d\u6742\u7684\u7b5b\u9009\u903b\u8f91\uff0c\u6ee1\u8db3\u5b9e\u9645\u5e94\u7528\u4e2d\u7684\u591a\u79cd\u9700\u6c42\u3002\u5728\u9009\u62e9\u7b5b\u9009\u65b9\u6cd5\u65f6\uff0c\u9700\u8981\u6839\u636e\u5177\u4f53\u9700\u6c42\u548c\u6027\u80fd\u8003\u8651\u8fdb\u884c\u9009\u62e9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u7b5b\u9009\u7279\u5b9a\u6761\u4ef6\u7684\u540d\u5b57\uff1f<\/strong><br \/>\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u3001filter\u51fd\u6570\u6216Pandas\u5e93\u6765\u7b5b\u9009\u7b26\u5408\u6761\u4ef6\u7684\u540d\u5b57\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u60f3\u7b5b\u9009\u51fa\u4ee5\u7279\u5b9a\u5b57\u6bcd\u5f00\u5934\u7684\u540d\u5b57\uff0c\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\uff1a<code>[name for name in names if name.startswith(&#39;A&#39;)]<\/code>\u3002\u8fd9\u6837\u53ef\u4ee5\u5feb\u901f\u521b\u5efa\u4e00\u4e2a\u65b0\u5217\u8868\uff0c\u5176\u4e2d\u4ec5\u5305\u542b\u7b26\u5408\u6761\u4ef6\u7684\u540d\u5b57\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u53ef\u4ee5\u4f7f\u7528\u54ea\u4e9b\u6570\u636e\u7ed3\u6784\u6765\u5b58\u50a8\u548c\u7b5b\u9009\u540d\u5b57\uff1f<\/strong><br \/>\u5e38\u89c1\u7684\u6570\u636e\u7ed3\u6784\u5305\u62ec\u5217\u8868\u3001\u5143\u7ec4\u548c\u96c6\u5408\u3002\u5217\u8868\u662f\u6700\u5e38\u7528\u7684\u9009\u62e9\uff0c\u56e0\u4e3a\u5b83\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u8fdb\u884c\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u3002\u4f60\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5b57\u5178\u6765\u5b58\u50a8\u540d\u5b57\u53ca\u5176\u76f8\u5173\u4fe1\u606f\uff08\u5982\u5e74\u9f84\u6216\u6027\u522b\uff09\uff0c\u8fd9\u6837\u53ef\u4ee5\u66f4\u65b9\u4fbf\u5730\u8fdb\u884c\u7b5b\u9009\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5728Python\u4e2d\u7b5b\u9009\u540d\u5b57\uff1f<\/strong><br \/>\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u4e00\u79cd\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u6765\u8fdb\u884c\u590d\u6742\u7684\u5b57\u7b26\u4e32\u5339\u914d\u3002\u5728Python\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528re\u6a21\u5757\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>re.findall(r&#39;^[A-Z]&#39;, name)<\/code>\u53ef\u4ee5\u7b5b\u9009\u51fa\u6240\u6709\u4ee5\u5927\u5199\u5b57\u6bcd\u5f00\u5934\u7684\u540d\u5b57\u3002\u8fd9\u79cd\u65b9\u6cd5\u7279\u522b\u9002\u5408\u9700\u8981\u590d\u6742\u6761\u4ef6\u7684\u7b5b\u9009\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5728Python\u4e2d\u7b5b\u9009\u51fa\u7b26\u5408\u6761\u4ef6\u7684\u540d\u5b57\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\uff0c\u4f8b\u5982\u5217\u8868\u89e3\u6790\u3001filter\u51fd\u6570\u548c\u6b63\u5219\u8868\u8fbe\u5f0f\u3002\u6bcf\u79cd\u65b9\u6cd5 [&hellip;]","protected":false},"author":3,"featured_media":1053163,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1053151"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1053151"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1053151\/revisions"}],"predecessor-version":[{"id":1053167,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1053151\/revisions\/1053167"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1053163"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1053151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1053151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1053151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}