{"id":1103786,"date":"2025-01-08T16:14:03","date_gmt":"2025-01-08T08:14:03","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1103786.html"},"modified":"2025-01-08T16:14:06","modified_gmt":"2025-01-08T08:14:06","slug":"python%e5%a6%82%e4%bd%95%e4%bb%8e%e5%88%97%e8%a1%a8%e4%b8%ad%e7%9a%84%e5%ad%97%e5%85%b8%e6%8f%90%e5%8f%96%e6%95%b0%e6%8d%ae","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1103786.html","title":{"rendered":"python\u5982\u4f55\u4ece\u5217\u8868\u4e2d\u7684\u5b57\u5178\u63d0\u53d6\u6570\u636e"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25065442\/568c15ee-e217-40ca-b6c9-700f0c9eb67e.webp\" alt=\"python\u5982\u4f55\u4ece\u5217\u8868\u4e2d\u7684\u5b57\u5178\u63d0\u53d6\u6570\u636e\" \/><\/p>\n<p><p> \u5728Python\u4e2d\uff0c\u4ece\u5217\u8868\u4e2d\u7684\u5b57\u5178\u63d0\u53d6\u6570\u636e\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\u3002<strong>\u6700\u5e38\u89c1\u7684\u65b9\u5f0f\u5305\u62ec\u4f7f\u7528for\u5faa\u73af\u3001\u5217\u8868\u63a8\u5bfc\u5f0f\u3001\u4ee5\u53camap\u51fd\u6570<\/strong>\u3002\u5176\u4e2d\uff0c<strong>\u4f7f\u7528for\u5faa\u73af\u53ef\u4ee5\u66f4\u7075\u6d3b\u5730\u5904\u7406\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784<\/strong>\u3002\u4f8b\u5982\uff0c\u5f53\u5217\u8868\u4e2d\u7684\u5b57\u5178\u7ed3\u6784\u590d\u6742\u6216\u5d4c\u5957\u5c42\u6b21\u8f83\u6df1\u65f6\uff0cfor\u5faa\u73af\u53ef\u4ee5\u8ba9\u4f60\u9010\u4e2a\u5143\u7d20\u5904\u7406\uff0c\u786e\u4fdd\u63d0\u53d6\u5230\u6240\u9700\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528for\u5faa\u73af\u63d0\u53d6\u6570\u636e<\/h3>\n<\/p>\n<p><p>for\u5faa\u73af\u662f\u4e00\u79cd\u975e\u5e38\u76f4\u89c2\u4e14\u7075\u6d3b\u7684\u65b9\u5f0f\u6765\u5904\u7406\u5217\u8868\u4e2d\u7684\u5b57\u5178\u3002\u901a\u8fc7for\u5faa\u73af\uff0c\u53ef\u4ee5\u9010\u4e2a\u904d\u5386\u5217\u8868\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5b57\u5178\uff0c\u5e76\u63d0\u53d6\u6240\u9700\u7684\u6570\u636e\u5b57\u6bb5\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">data = [<\/p>\n<p>    {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 25, &quot;city&quot;: &quot;New York&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Bob&quot;, &quot;age&quot;: 30, &quot;city&quot;: &quot;Chicago&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Charlie&quot;, &quot;age&quot;: 35, &quot;city&quot;: &quot;San Francisco&quot;}<\/p>\n<p>]<\/p>\n<p>names = []<\/p>\n<p>for item in data:<\/p>\n<p>    names.append(item[&quot;name&quot;])<\/p>\n<p>print(names)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c<strong>\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u5b57\u5178\u7684\u5217\u8868\uff0c\u5e76\u4f7f\u7528for\u5faa\u73af\u904d\u5386\u6bcf\u4e2a\u5b57\u5178\uff0c\u63d0\u53d6&quot;name&quot;\u5b57\u6bb5\u7684\u503c\uff0c\u5e76\u5c06\u5176\u6dfb\u52a0\u5230names\u5217\u8868\u4e2d<\/strong>\u3002\u6700\u7ec8\u8f93\u51fa\u7684\u7ed3\u679c\u5c06\u662f\u4e00\u4e2a\u5305\u542b\u6240\u6709\u540d\u5b57\u7684\u5217\u8868\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u63d0\u53d6\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u5217\u8868\u63a8\u5bfc\u5f0f\u662fPython\u4e2d\u7684\u4e00\u79cd\u7b80\u6d01\u4e14\u9ad8\u6548\u7684\u65b9\u5f0f\uff0c\u7528\u4e8e\u751f\u6210\u65b0\u7684\u5217\u8868\u3002\u76f8\u6bd4\u4e8efor\u5faa\u73af\uff0c\u5217\u8868\u63a8\u5bfc\u5f0f\u53ef\u4ee5\u5728\u4e00\u884c\u4ee3\u7801\u4e2d\u5b8c\u6210\u76f8\u540c\u7684\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">data = [<\/p>\n<p>    {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 25, &quot;city&quot;: &quot;New York&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Bob&quot;, &quot;age&quot;: 30, &quot;city&quot;: &quot;Chicago&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Charlie&quot;, &quot;age&quot;: 35, &quot;city&quot;: &quot;San Francisco&quot;}<\/p>\n<p>]<\/p>\n<p>names = [item[&quot;name&quot;] for item in data]<\/p>\n<p>print(names)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<strong>\u6211\u4eec\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u5728\u4e00\u884c\u4ee3\u7801\u4e2d\u63d0\u53d6\u6240\u6709\u5b57\u5178\u4e2d\u7684&quot;name&quot;\u5b57\u6bb5\u503c<\/strong>\u3002\u8fd9\u79cd\u65b9\u5f0f\u4e0d\u4ec5\u7b80\u6d01\uff0c\u800c\u4e14\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u65f6\u66f4\u9ad8\u6548\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528map\u51fd\u6570\u63d0\u53d6\u6570\u636e<\/h3>\n<\/p>\n<p><p>map\u51fd\u6570\u662fPython\u5185\u7f6e\u7684\u9ad8\u9636\u51fd\u6570\u4e4b\u4e00\uff0c\u7528\u4e8e\u5bf9\u53ef\u8fed\u4ee3\u5bf9\u8c61\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u5e94\u7528\u6307\u5b9a\u7684\u51fd\u6570\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u8fed\u4ee3\u5668\u3002\u5bf9\u4e8e\u5217\u8868\u4e2d\u7684\u5b57\u5178\uff0c\u53ef\u4ee5\u4f7f\u7528map\u51fd\u6570\u7ed3\u5408lambda\u8868\u8fbe\u5f0f\u6765\u63d0\u53d6\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">data = [<\/p>\n<p>    {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 25, &quot;city&quot;: &quot;New York&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Bob&quot;, &quot;age&quot;: 30, &quot;city&quot;: &quot;Chicago&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Charlie&quot;, &quot;age&quot;: 35, &quot;city&quot;: &quot;San Francisco&quot;}<\/p>\n<p>]<\/p>\n<p>names = list(map(lambda item: item[&quot;name&quot;], data))<\/p>\n<p>print(names)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c<strong>\u6211\u4eec\u4f7f\u7528map\u51fd\u6570\u548clambda\u8868\u8fbe\u5f0f\u6765\u63d0\u53d6\u6bcf\u4e2a\u5b57\u5178\u4e2d\u7684&quot;name&quot;\u5b57\u6bb5\u503c\uff0c\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u5217\u8868<\/strong>\u3002\u8fd9\u79cd\u65b9\u6cd5\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u65f6\u540c\u6837\u5177\u6709\u5f88\u9ad8\u7684\u6548\u7387\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5904\u7406\u5d4c\u5957\u5b57\u5178\u7684\u63d0\u53d6<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u5019\uff0c\u5217\u8868\u4e2d\u7684\u5b57\u5178\u53ef\u80fd\u4f1a\u5305\u542b\u5d4c\u5957\u7684\u5b57\u5178\u7ed3\u6784\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u7ed3\u5408for\u5faa\u73af\u548c\u9012\u5f52\u51fd\u6570\u6765\u63d0\u53d6\u5d4c\u5957\u5b57\u5178\u4e2d\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">data = [<\/p>\n<p>    {&quot;name&quot;: &quot;Alice&quot;, &quot;det<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>ls&quot;: {&quot;age&quot;: 25, &quot;city&quot;: &quot;New York&quot;}},<\/p>\n<p>    {&quot;name&quot;: &quot;Bob&quot;, &quot;details&quot;: {&quot;age&quot;: 30, &quot;city&quot;: &quot;Chicago&quot;}},<\/p>\n<p>    {&quot;name&quot;: &quot;Charlie&quot;, &quot;details&quot;: {&quot;age&quot;: 35, &quot;city&quot;: &quot;San Francisco&quot;}}<\/p>\n<p>]<\/p>\n<p>def extract_nested(data, key):<\/p>\n<p>    result = []<\/p>\n<p>    for item in data:<\/p>\n<p>        if key in item:<\/p>\n<p>            result.append(item[key])<\/p>\n<p>        elif isinstance(item, dict):<\/p>\n<p>            for k, v in item.items():<\/p>\n<p>                if isinstance(v, dict):<\/p>\n<p>                    result.extend(extract_nested([v], key))<\/p>\n<p>    return result<\/p>\n<p>ages = extract_nested(data, &quot;age&quot;)<\/p>\n<p>print(ages)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<strong>\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u9012\u5f52\u51fd\u6570extract_nested\u6765\u63d0\u53d6\u5d4c\u5957\u5b57\u5178\u4e2d\u7684\u6570\u636e<\/strong>\u3002\u8be5\u51fd\u6570\u4f1a\u904d\u5386\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5b57\u5178\uff0c\u5e76\u9012\u5f52\u5730\u67e5\u627e\u5d4c\u5957\u5b57\u5178\u4e2d\u7684\u76ee\u6807\u952e\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u7ed3\u5408\u6761\u4ef6\u8fc7\u6ee4\u8fdb\u884c\u6570\u636e\u63d0\u53d6<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u6839\u636e\u7279\u5b9a\u6761\u4ef6\u8fc7\u6ee4\u5217\u8868\u4e2d\u7684\u5b57\u5178\uff0c\u5e76\u63d0\u53d6\u7b26\u5408\u6761\u4ef6\u7684\u6570\u636e\u3002\u8fd9\u65f6\u53ef\u4ee5\u7ed3\u5408for\u5faa\u73af\u6216\u5217\u8868\u63a8\u5bfc\u5f0f\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">data = [<\/p>\n<p>    {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 25, &quot;city&quot;: &quot;New York&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Bob&quot;, &quot;age&quot;: 30, &quot;city&quot;: &quot;Chicago&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Charlie&quot;, &quot;age&quot;: 35, &quot;city&quot;: &quot;San Francisco&quot;}<\/p>\n<p>]<\/p>\n<h2><strong>\u63d0\u53d6\u5e74\u9f84\u5927\u4e8e30\u7684\u4eba\u7684\u540d\u5b57<\/strong><\/h2>\n<p>names = [item[&quot;name&quot;] for item in data if item[&quot;age&quot;] &gt; 30]<\/p>\n<p>print(names)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<strong>\u6211\u4eec\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u7ed3\u5408\u6761\u4ef6\u8fc7\u6ee4\uff0c\u63d0\u53d6\u5e74\u9f84\u5927\u4e8e30\u7684\u4eba\u7684\u540d\u5b57<\/strong>\u3002\u8fd9\u79cd\u65b9\u6cd5\u975e\u5e38\u7b80\u6d01\u4e14\u9ad8\u6548\uff0c\u9002\u7528\u4e8e\u9700\u8981\u8fdb\u884c\u6761\u4ef6\u8fc7\u6ee4\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u63d0\u53d6\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u66f4\u590d\u6742\u7684\u6570\u636e\u63d0\u53d6\u9700\u6c42\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\uff0c\u5982Pandas\u3002Pandas\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u5e93\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u636e\u64cd\u4f5c\u529f\u80fd\uff0c\u53ef\u4ee5\u8f7b\u677e\u5904\u7406\u5217\u8868\u4e2d\u7684\u5b57\u5178\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>data = [<\/p>\n<p>    {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 25, &quot;city&quot;: &quot;New York&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Bob&quot;, &quot;age&quot;: 30, &quot;city&quot;: &quot;Chicago&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Charlie&quot;, &quot;age&quot;: 35, &quot;city&quot;: &quot;San Francisco&quot;}<\/p>\n<p>]<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u63d0\u53d6\u6240\u6709\u540d\u5b57<\/strong><\/h2>\n<p>names = df[&quot;name&quot;].tolist()<\/p>\n<p>print(names)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<strong>\u6211\u4eec\u4f7f\u7528Pandas\u5c06\u5217\u8868\u8f6c\u6362\u4e3aDataFrame\uff0c\u5e76\u901a\u8fc7\u5217\u540d\u76f4\u63a5\u63d0\u53d6\u6570\u636e<\/strong>\u3002\u8fd9\u79cd\u65b9\u6cd5\u975e\u5e38\u9002\u5408\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\uff0c\u5e76\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u636e\u64cd\u4f5c\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u4ece\u5217\u8868\u4e2d\u7684\u5b57\u5178\u63d0\u53d6\u6570\u636e\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\uff0c\u5305\u62ec\u4f7f\u7528for\u5faa\u73af\u3001\u5217\u8868\u63a8\u5bfc\u5f0f\u3001map\u51fd\u6570\u3001\u9012\u5f52\u51fd\u6570\u3001\u6761\u4ef6\u8fc7\u6ee4\u4ee5\u53ca\u7b2c\u4e09\u65b9\u5e93Pandas\u3002<strong>\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u6570\u636e\u7ed3\u6784\u548c\u63d0\u53d6\u9700\u6c42<\/strong>\u3002for\u5faa\u73af\u9002\u7528\u4e8e\u5904\u7406\u590d\u6742\u6216\u5d4c\u5957\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5217\u8868\u63a8\u5bfc\u5f0f\u548cmap\u51fd\u6570\u9002\u5408\u7b80\u6d01\u9ad8\u6548\u7684\u6570\u636e\u63d0\u53d6\uff0c\u9012\u5f52\u51fd\u6570\u53ef\u4ee5\u5904\u7406\u5d4c\u5957\u5b57\u5178\uff0c\u6761\u4ef6\u8fc7\u6ee4\u9002\u7528\u4e8e\u6839\u636e\u7279\u5b9a\u6761\u4ef6\u63d0\u53d6\u6570\u636e\uff0c\u800cPandas\u5219\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u64cd\u4f5c\u529f\u80fd\uff0c\u9002\u5408\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u638c\u63e1\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u7075\u6d3b\u5730\u5904\u7406\u548c\u63d0\u53d6\u5217\u8868\u4e2d\u7684\u5b57\u5178\u6570\u636e\uff0c\u4ee5\u6ee1\u8db3\u5404\u79cd\u6570\u636e\u5904\u7406\u9700\u6c42\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u7ed3\u5408\u4e0d\u540c\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u63d0\u9ad8\u6570\u636e\u63d0\u53d6\u7684\u6548\u7387\u548c\u7075\u6d3b\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u4ece\u5b57\u5178\u5217\u8868\u4e2d\u63d0\u53d6\u7279\u5b9a\u952e\u7684\u503c\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u5982\u679c\u4f60\u6709\u4e00\u4e2a\u5305\u542b\u5b57\u5178\u7684\u5217\u8868\uff0c\u5e76\u4e14\u60f3\u63d0\u53d6\u7279\u5b9a\u952e\u7684\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u3002\u5047\u8bbe\u4f60\u7684\u5217\u8868\u540d\u4e3a<code>data<\/code>\uff0c\u5e76\u4e14\u4f60\u60f3\u63d0\u53d6\u6240\u6709\u5b57\u5178\u4e2d<code>&#39;name&#39;<\/code>\u952e\u7684\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u4ee3\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">names = [item[&#39;name&#39;] for item in data]\n<\/code><\/pre>\n<p>\u8fd9\u6837\uff0c<code>names<\/code>\u5217\u8868\u5c06\u5305\u542b\u6240\u6709\u5b57\u5178\u4e2d<code>&#39;name&#39;<\/code>\u952e\u5bf9\u5e94\u7684\u503c\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u5b57\u5178\u5217\u8868\u4e2d\u7f3a\u5931\u7684\u952e\uff1f<\/strong><br \/>\u5728\u63d0\u53d6\u6570\u636e\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u67d0\u4e9b\u5b57\u5178\u7f3a\u5c11\u7279\u5b9a\u7684\u952e\u3002\u4e3a\u4e86\u5b89\u5168\u5730\u5904\u7406\u8fd9\u79cd\u60c5\u51b5\uff0c\u53ef\u4ee5\u4f7f\u7528<code>dict.get()<\/code>\u65b9\u6cd5\u3002\u6bd4\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">names = [item.get(&#39;name&#39;, &#39;\u672a\u77e5&#39;) for item in data]\n<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5982\u679c\u67d0\u4e2a\u5b57\u5178\u6ca1\u6709<code>&#39;name&#39;<\/code>\u952e\uff0c<code>names<\/code>\u5217\u8868\u4e2d\u5c06\u586b\u5145\u4e3a<code>&#39;\u672a\u77e5&#39;<\/code>\u3002<\/p>\n<p><strong>\u5982\u4f55\u4ece\u5b57\u5178\u5217\u8868\u4e2d\u63d0\u53d6\u7b26\u5408\u6761\u4ef6\u7684\u9879\uff1f<\/strong><br \/>\u5982\u679c\u60f3\u4ece\u5b57\u5178\u5217\u8868\u4e2d\u63d0\u53d6\u7b26\u5408\u7279\u5b9a\u6761\u4ef6\u7684\u9879\uff0c\u53ef\u4ee5\u7ed3\u5408\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u548c\u6761\u4ef6\u8bed\u53e5\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u53ea\u60f3\u63d0\u53d6<code>&#39;age&#39;<\/code>\u5927\u4e8e20\u7684\u5b57\u5178\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u4ee3\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">adults = [item for item in data if item[&#39;age&#39;] &gt; 20]\n<\/code><\/pre>\n<p>\u8fd9\u6837\uff0c<code>adults<\/code>\u5217\u8868\u5c06\u4ec5\u5305\u542b<code>&#39;age&#39;<\/code>\u5927\u4e8e20\u7684\u5b57\u5178\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u4ece\u5217\u8868\u4e2d\u7684\u5b57\u5178\u63d0\u53d6\u6570\u636e\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\u3002\u6700\u5e38\u89c1\u7684\u65b9\u5f0f\u5305\u62ec\u4f7f\u7528for\u5faa\u73af\u3001\u5217\u8868\u63a8\u5bfc\u5f0f\u3001\u4ee5\u53ca [&hellip;]","protected":false},"author":3,"featured_media":1103795,"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\/1103786"}],"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=1103786"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1103786\/revisions"}],"predecessor-version":[{"id":1103796,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1103786\/revisions\/1103796"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1103795"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1103786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1103786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1103786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}