{"id":1121122,"date":"2025-01-08T19:05:44","date_gmt":"2025-01-08T11:05:44","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1121122.html"},"modified":"2025-01-08T19:05:47","modified_gmt":"2025-01-08T11:05:47","slug":"python%e5%a6%82%e4%bd%95%e5%88%a0%e9%99%a4%e5%88%97%e8%a1%a8%e4%b8%ad%e7%9a%84%e6%9c%80%e5%a4%a7%e5%80%bc","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1121122.html","title":{"rendered":"python\u5982\u4f55\u5220\u9664\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25083511\/11aefd0e-c3fc-4e89-abc6-37cdf856816c.webp\" alt=\"python\u5982\u4f55\u5220\u9664\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\" \/><\/p>\n<p><p> <strong>\u8981\u5728Python\u4e2d\u5220\u9664\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u3001\u5faa\u73af\u904d\u5386\u3001\u5217\u8868\u63a8\u5bfc\u5f0f\u3002\u4ee5\u4e0b\u6211\u4eec\u5c06\u8be6\u7ec6\u8bb2\u89e3\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5<\/strong>\u3002\u9996\u5148\uff0c\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u662f\u6700\u7b80\u5355\u4e14\u63a8\u8350\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u5177\u6709\u826f\u597d\u7684\u53ef\u8bfb\u6027\u548c\u9ad8\u6548\u7684\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5185\u7f6e\u51fd\u6570\u6cd5<\/p>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u8bb8\u591a\u5185\u7f6e\u51fd\u6570\uff0c\u53ef\u4ee5\u8ba9\u6211\u4eec\u8f7b\u677e\u5730\u64cd\u4f5c\u5217\u8868\u3002\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u6765\u5220\u9664\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u4f7f\u7528<code>max()<\/code>\u51fd\u6570\u627e\u5230\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u3002<\/li>\n<li>\u4f7f\u7528<code>remove()<\/code>\u51fd\u6570\u5220\u9664\u627e\u5230\u7684\u6700\u5927\u503c\u3002<\/li>\n<\/ol>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7b80\u5355\u6613\u61c2\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_list = [3, 5, 7, 2, 8, 10, 1]<\/p>\n<p>max_value = max(my_list)<\/p>\n<p>my_list.remove(max_value)<\/p>\n<p>print(my_list)  # \u8f93\u51fa\uff1a[3, 5, 7, 2, 8, 1]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u89e3\u91ca<\/strong>\uff1a\u9996\u5148\uff0c\u6211\u4eec\u4f7f\u7528<code>max()<\/code>\u51fd\u6570\u627e\u51fa\u5217\u8868\u4e2d\u6700\u5927\u7684\u5143\u7d20\u3002\u63a5\u7740\uff0c\u4f7f\u7528<code>remove()<\/code>\u51fd\u6570\u5c06\u8fd9\u4e2a\u6700\u5927\u503c\u4ece\u5217\u8868\u4e2d\u5220\u9664\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c<code>remove()<\/code>\u51fd\u6570\u53ea\u4f1a\u5220\u9664\u5217\u8868\u4e2d\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u8be5\u5143\u7d20\u3002\u5982\u679c\u5217\u8868\u4e2d\u6709\u91cd\u590d\u7684\u6700\u5927\u503c\uff0c\u53ea\u4f1a\u5220\u9664\u7b2c\u4e00\u4e2a\u3002<\/p>\n<\/p>\n<hr>\n<p><h3>\u4e00\u3001\u5185\u7f6e\u51fd\u6570\u6cd5<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u662f\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3aPython\u5185\u7f6e\u51fd\u6570\u63d0\u4f9b\u4e86\u826f\u597d\u7684\u6027\u80fd\u548c\u53ef\u8bfb\u6027\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u7684\u6b65\u9aa4\u548c\u89e3\u91ca\uff1a<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528<code>max()<\/code>\u51fd\u6570\u627e\u5230\u6700\u5927\u503c<\/h4>\n<\/p>\n<p><p><code>max()<\/code>\u51fd\u6570\u662fPython\u5185\u7f6e\u7684\u4e00\u4e2a\u51fd\u6570\uff0c\u7528\u6765\u8fd4\u56de\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u3002\u5176\u4f7f\u7528\u65b9\u6cd5\u975e\u5e38\u7b80\u5355\uff0c\u76f4\u63a5\u4f20\u5165\u5217\u8868\u5373\u53ef\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_list = [3, 5, 7, 2, 8, 10, 1]<\/p>\n<p>max_value = max(my_list)<\/p>\n<p>print(max_value)  # \u8f93\u51fa\uff1a10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c<code>max()<\/code>\u51fd\u6570\u4f1a\u904d\u5386\u6574\u4e2a\u5217\u8868\uff0c\u5e76\u8fd4\u56de\u6700\u5927\u7684\u90a3\u4e2a\u5143\u7d20\u3002\u5728\u6211\u4eec\u7684\u4f8b\u5b50\u4e2d\uff0c\u6700\u5927\u503c\u662f10\u3002<\/p>\n<\/p>\n<p><h4>2. \u4f7f\u7528<code>remove()<\/code>\u51fd\u6570\u5220\u9664\u6700\u5927\u503c<\/h4>\n<\/p>\n<p><p><code>remove()<\/code>\u51fd\u6570\u540c\u6837\u662fPython\u5185\u7f6e\u7684\u4e00\u4e2a\u51fd\u6570\uff0c\u7528\u6765\u5220\u9664\u5217\u8868\u4e2d\u7684\u67d0\u4e2a\u503c\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5b83\u53ea\u4f1a\u5220\u9664\u7b2c\u4e00\u4e2a\u5339\u914d\u7684\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_list.remove(max_value)<\/p>\n<p>print(my_list)  # \u8f93\u51fa\uff1a[3, 5, 7, 2, 8, 1]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5c06\u524d\u9762\u627e\u5230\u7684\u6700\u5927\u503c\u4f20\u7ed9<code>remove()<\/code>\u51fd\u6570\uff0c\u8fd9\u6837\u5217\u8868\u4e2d\u7684\u7b2c\u4e00\u4e2a10\u5c31\u88ab\u5220\u9664\u4e86\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u5faa\u73af\u904d\u5386\u6cd5<\/h3>\n<\/p>\n<p><p>\u867d\u7136\u5185\u7f6e\u51fd\u6570\u6cd5\u662f\u6700\u7b80\u5355\u7684\uff0c\u4f46\u662f\u5728\u67d0\u4e9b\u7279\u5b9a\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u66f4\u7075\u6d3b\u7684\u89e3\u51b3\u65b9\u6848\u3002\u5faa\u73af\u904d\u5386\u6cd5\u662f\u53e6\u4e00\u79cd\u5220\u9664\u5217\u8868\u4e2d\u6700\u5927\u503c\u7684\u65b9\u6cd5\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u7684\u6b65\u9aa4\u548c\u89e3\u91ca\uff1a<\/p>\n<\/p>\n<p><h4>1. \u904d\u5386\u627e\u5230\u6700\u5927\u503c<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e2a\u5faa\u73af\u6765\u904d\u5386\u5217\u8868\uff0c\u627e\u5230\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_list = [3, 5, 7, 2, 8, 10, 1]<\/p>\n<p>max_value = my_list[0]<\/p>\n<p>for num in my_list:<\/p>\n<p>    if num &gt; max_value:<\/p>\n<p>        max_value = num<\/p>\n<p>print(max_value)  # \u8f93\u51fa\uff1a10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5047\u5b9a\u7b2c\u4e00\u4e2a\u5143\u7d20\u662f\u6700\u5927\u7684\uff0c\u7136\u540e\u901a\u8fc7\u904d\u5386\u5217\u8868\u66f4\u65b0\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<p><h4>2. \u518d\u6b21\u904d\u5386\u5220\u9664\u6700\u5927\u503c<\/h4>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u518d\u6b21\u904d\u5386\u5217\u8868\uff0c\u627e\u5230\u5e76\u5220\u9664\u8fd9\u4e2a\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for i in range(len(my_list)):<\/p>\n<p>    if my_list[i] == max_value:<\/p>\n<p>        del my_list[i]<\/p>\n<p>        break<\/p>\n<p>print(my_list)  # \u8f93\u51fa\uff1a[3, 5, 7, 2, 8, 1]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>del<\/code>\u5173\u952e\u5b57\u5220\u9664\u627e\u5230\u7684\u6700\u5927\u503c\uff0c\u5e76\u4e14\u4f7f\u7528<code>break<\/code>\u8bed\u53e5\u6765\u7ec8\u6b62\u5faa\u73af\uff0c\u4ee5\u786e\u4fdd\u53ea\u5220\u9664\u7b2c\u4e00\u4e2a\u5339\u914d\u7684\u503c\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u5217\u8868\u63a8\u5bfc\u5f0f\u6cd5<\/h3>\n<\/p>\n<p><p>\u5217\u8868\u63a8\u5bfc\u5f0f\u662f\u4e00\u79cd\u7b80\u6d01\u4e14\u4f18\u96c5\u7684Python\u8bed\u6cd5\u3002\u5b83\u53ef\u4ee5\u7528\u6765\u751f\u6210\u65b0\u7684\u5217\u8868\uff0c\u6ee1\u8db3\u7279\u5b9a\u7684\u6761\u4ef6\u3002\u6211\u4eec\u4e5f\u53ef\u4ee5\u7528\u5b83\u6765\u5220\u9664\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<p><h4>1. \u627e\u5230\u6700\u5927\u503c<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u4ecd\u7136\u9700\u8981\u4f7f\u7528<code>max()<\/code>\u51fd\u6570\u627e\u5230\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_list = [3, 5, 7, 2, 8, 10, 1]<\/p>\n<p>max_value = max(my_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u751f\u6210\u65b0\u7684\u5217\u8868<\/h4>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u5217\u8868\uff0c\u8fd9\u4e2a\u5217\u8868\u4e2d\u4e0d\u5305\u542b\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">new_list = [num for num in my_list if num != max_value]<\/p>\n<p>print(new_list)  # \u8f93\u51fa\uff1a[3, 5, 7, 2, 8, 1]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u904d\u5386\u4e86\u539f\u59cb\u5217\u8868\uff0c\u5e76\u4e14\u53ea\u4fdd\u7559\u90a3\u4e9b\u4e0d\u7b49\u4e8e\u6700\u5927\u503c\u7684\u5143\u7d20\uff0c\u751f\u6210\u4e86\u4e00\u4e2a\u65b0\u7684\u5217\u8868\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528<code>filter()<\/code>\u51fd\u6570<\/h3>\n<\/p>\n<p><p><code>filter()<\/code>\u51fd\u6570\u662fPython\u5185\u7f6e\u7684\u4e00\u4e2a\u9ad8\u9636\u51fd\u6570\uff0c\u7528\u4e8e\u8fc7\u6ee4\u5e8f\u5217\u4e2d\u7684\u5143\u7d20\u3002\u6211\u4eec\u4e5f\u53ef\u4ee5\u7528\u5b83\u6765\u5220\u9664\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<p><h4>1. \u627e\u5230\u6700\u5927\u503c<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u4ecd\u7136\u9700\u8981\u4f7f\u7528<code>max()<\/code>\u51fd\u6570\u627e\u5230\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_list = [3, 5, 7, 2, 8, 10, 1]<\/p>\n<p>max_value = max(my_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528<code>filter()<\/code>\u51fd\u6570\u751f\u6210\u65b0\u7684\u5217\u8868<\/h4>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u4f7f\u7528<code>filter()<\/code>\u51fd\u6570\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u5217\u8868\uff0c\u8fd9\u4e2a\u5217\u8868\u4e2d\u4e0d\u5305\u542b\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">new_list = list(filter(lambda x: x != max_value, my_list))<\/p>\n<p>print(new_list)  # \u8f93\u51fa\uff1a[3, 5, 7, 2, 8, 1]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u4e00\u4e2a<code>lambda<\/code>\u51fd\u6570\u6765\u68c0\u67e5\u5217\u8868\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\uff0c\u53ea\u6709\u90a3\u4e9b\u4e0d\u7b49\u4e8e\u6700\u5927\u503c\u7684\u5143\u7d20\u4f1a\u88ab\u4fdd\u7559\u4e0b\u6765\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u4f7f\u7528<code>collections.Counter<\/code><\/h3>\n<\/p>\n<p><p><code>collections.Counter<\/code>\u662fPython\u6807\u51c6\u5e93\u4e2d\u7684\u4e00\u4e2a\u7c7b\uff0c\u9002\u7528\u4e8e\u8ba1\u6570\u548c\u96c6\u5408\u64cd\u4f5c\u3002\u6211\u4eec\u4e5f\u53ef\u4ee5\u7528\u5b83\u6765\u5220\u9664\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<p><h4>1. \u627e\u5230\u6700\u5927\u503c<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u4ecd\u7136\u9700\u8981\u4f7f\u7528<code>max()<\/code>\u51fd\u6570\u627e\u5230\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from collections import Counter<\/p>\n<p>my_list = [3, 5, 7, 2, 8, 10, 1]<\/p>\n<p>max_value = max(my_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528<code>Counter<\/code>\u751f\u6210\u65b0\u7684\u5217\u8868<\/h4>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u4f7f\u7528<code>Counter<\/code>\u7c7b\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u5217\u8868\uff0c\u8fd9\u4e2a\u5217\u8868\u4e2d\u4e0d\u5305\u542b\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">counter = Counter(my_list)<\/p>\n<p>counter[max_value] -= 1<\/p>\n<p>new_list = list(counter.elements())<\/p>\n<p>print(new_list)  # \u8f93\u51fa\uff1a[3, 5, 7, 2, 8, 1]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5bf9\u5217\u8868\u8fdb\u884c\u8ba1\u6570\uff0c\u7136\u540e\u51cf\u5c11\u6700\u5927\u503c\u7684\u8ba1\u6570\uff0c\u6700\u540e\u4f7f\u7528<code>elements()<\/code>\u65b9\u6cd5\u751f\u6210\u65b0\u7684\u5217\u8868\u3002<\/p>\n<\/p>\n<p><h3>\u7ed3\u8bba<\/h3>\n<\/p>\n<p><p>\u65e0\u8bba\u4f7f\u7528\u54ea\u79cd\u65b9\u6cd5\uff0c\u5220\u9664\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u90fd\u662f\u4e00\u4e2a\u76f8\u5bf9\u7b80\u5355\u7684\u64cd\u4f5c\u3002<strong>\u5185\u7f6e\u51fd\u6570\u6cd5<\/strong>\u662f\u6700\u63a8\u8350\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u6700\u4e3a\u7b80\u6d01\u548c\u9ad8\u6548\u3002\u800c<strong>\u5faa\u73af\u904d\u5386\u6cd5<\/strong>\u548c<strong>\u5217\u8868\u63a8\u5bfc\u5f0f\u6cd5<\/strong>\u5219\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u7075\u6d3b\u6027\uff0c\u53ef\u4ee5\u5e94\u5bf9\u4e00\u4e9b\u7279\u6b8a\u7684\u9700\u6c42\u3002<strong>filter()\u51fd\u6570<\/strong>\u548c<strong>collections.Counter<\/strong>\u65b9\u6cd5\u4e5f\u63d0\u4f9b\u4e86\u4e0d\u540c\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u9002\u7528\u4e8e\u7279\u5b9a\u573a\u666f\u3002<\/p>\n<\/p>\n<p><p>\u603b\u7684\u6765\u8bf4\uff0c\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u9700\u6c42\u548c\u7f16\u7a0b\u4e60\u60ef\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u591f\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7406\u89e3\u5982\u4f55\u5728Python\u4e2d\u5220\u9664\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u627e\u5230\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>max()<\/code>\u51fd\u6570\u6765\u627e\u5230\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u3002\u4f8b\u5982\uff0c\u7ed9\u5b9a\u4e00\u4e2a\u5217\u8868<code>my_list = [3, 1, 4, 1, 5, 9]<\/code>\uff0c\u53ef\u4ee5\u901a\u8fc7<code>max_value = max(my_list)<\/code>\u6765\u83b7\u53d6\u6700\u5927\u503c9\u3002<\/p>\n<p><strong>\u4f7f\u7528\u4ec0\u4e48\u65b9\u6cd5\u53ef\u4ee5\u5220\u9664\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\uff1f<\/strong><br \/>\u5220\u9664\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u53ef\u4ee5\u4f7f\u7528<code>remove()<\/code>\u65b9\u6cd5\u3002\u627e\u5230\u6700\u5927\u503c\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7<code>my_list.remove(max_value)<\/code>\u5c06\u5176\u4ece\u5217\u8868\u4e2d\u5220\u9664\u3002\u4f8b\u5982\uff0c<code>my_list.remove(max(my_list))<\/code>\u5c06\u5220\u9664\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u3002<\/p>\n<p><strong>\u5982\u679c\u5217\u8868\u4e2d\u6709\u591a\u4e2a\u76f8\u540c\u7684\u6700\u5927\u503c\uff0c\u5982\u4f55\u5220\u9664\u6240\u6709\u6700\u5927\u503c\uff1f<\/strong><br \/>\u8981\u5220\u9664\u5217\u8868\u4e2d\u6240\u6709\u7684\u6700\u5927\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u3002\u9996\u5148\u627e\u5230\u6700\u5927\u503c\uff0c\u7136\u540e\u521b\u5efa\u4e00\u4e2a\u65b0\u5217\u8868\uff0c\u5176\u4e2d\u4e0d\u5305\u542b\u6700\u5927\u503c\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">my_list = [3, 1, 4, 1, 5, 9, 9]\nmax_value = max(my_list)\nnew_list = [x for x in my_list if x != max_value]\n<\/code><\/pre>\n<p>\u8fd9\u6837\uff0c<code>new_list<\/code>\u5c06\u53ea\u5305\u542b\u4e0d\u7b49\u4e8e\u6700\u5927\u503c\u7684\u5143\u7d20\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5728Python\u4e2d\u5220\u9664\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u3001\u5faa\u73af\u904d\u5386\u3001\u5217\u8868\u63a8\u5bfc\u5f0f\u3002\u4ee5\u4e0b\u6211\u4eec\u5c06\u8be6\u7ec6 [&hellip;]","protected":false},"author":3,"featured_media":1121127,"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\/1121122"}],"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=1121122"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1121122\/revisions"}],"predecessor-version":[{"id":1121130,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1121122\/revisions\/1121130"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1121127"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1121122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1121122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1121122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}