{"id":1042076,"date":"2024-12-31T12:54:25","date_gmt":"2024-12-31T04:54:25","guid":{"rendered":""},"modified":"2024-12-31T12:54:28","modified_gmt":"2024-12-31T04:54:28","slug":"python3%e4%b8%ad%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e5%88%97%e8%a1%a8%e6%8e%92%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1042076.html","title":{"rendered":"python3\u4e2d\u5982\u4f55\u5b9e\u73b0\u5217\u8868\u6392\u5e8f"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/724270fe-15e1-4099-9920-ce1577a2b466.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python3\u4e2d\u5982\u4f55\u5b9e\u73b0\u5217\u8868\u6392\u5e8f\" \/><\/p>\n<p><p> \u5728Python3\u4e2d\u5b9e\u73b0\u5217\u8868\u6392\u5e8f\u7684\u65b9\u6cd5\u6709\u5f88\u591a\u79cd\uff0c\u5177\u4f53\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u7684<code>sort()<\/code>\u65b9\u6cd5\u3001<code>sorted()<\/code>\u51fd\u6570\u3001\u4ee5\u53ca\u81ea\u5b9a\u4e49\u6392\u5e8f\u51fd\u6570\u7b49\u3002<strong>\u4f7f\u7528sort()\u65b9\u6cd5\u3001\u4f7f\u7528sorted()\u51fd\u6570\u3001\u5229\u7528lambda\u51fd\u6570\u8fdb\u884c\u81ea\u5b9a\u4e49\u6392\u5e8f<\/strong>\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u8ba8\u8bba\u8fd9\u51e0\u79cd\u65b9\u6cd5\u4e2d\u7684\u4e00\u79cd\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528<code>sort()<\/code>\u65b9\u6cd5\u662f\u6700\u5e38\u89c1\u7684\u6392\u5e8f\u65b9\u6cd5\u4e4b\u4e00\uff0c<code>sort()<\/code>\u65b9\u6cd5\u4f1a\u5bf9\u5217\u8868\u8fdb\u884c\u539f\u5730\u6392\u5e8f\uff08\u5373\u4e0d\u4f1a\u521b\u5efa\u65b0\u7684\u5217\u8868\uff09\uff0c\u56e0\u6b64\u5b83\u7684\u6548\u7387\u5f88\u9ad8\u3002<\/strong><\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528sort()\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p><code>sort()<\/code>\u65b9\u6cd5\u662fPython\u5217\u8868\u7684\u5185\u7f6e\u65b9\u6cd5\uff0c\u80fd\u591f\u5bf9\u5217\u8868\u4e2d\u7684\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\u3002\u5b83\u662f\u4e00\u4e2a\u539f\u5730\u6392\u5e8f\u65b9\u6cd5\uff0c\u8fd9\u610f\u5473\u7740\u6392\u5e8f\u64cd\u4f5c\u4f1a\u76f4\u63a5\u4fee\u6539\u539f\u59cb\u5217\u8868\uff0c\u800c\u4e0d\u662f\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u5217\u8868\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c<code>sort()<\/code>\u65b9\u6cd5\u4f1a\u6309\u7167\u5347\u5e8f\u5bf9\u5217\u8868\u8fdb\u884c\u6392\u5e8f\uff0c\u4f46\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e<code>reverse<\/code>\u53c2\u6570\u4e3a<code>True<\/code>\u6765\u5b9e\u73b0\u964d\u5e8f\u6392\u5e8f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b1\uff1a\u5bf9\u6570\u5b57\u5217\u8868\u8fdb\u884c\u6392\u5e8f<\/p>\n<p>numbers = [5, 2, 9, 1, 5, 6]<\/p>\n<p>numbers.sort()<\/p>\n<p>print(numbers)  # \u8f93\u51fa\uff1a[1, 2, 5, 5, 6, 9]<\/p>\n<h2><strong>\u793a\u4f8b2\uff1a\u5bf9\u5b57\u7b26\u4e32\u5217\u8868\u8fdb\u884c\u6392\u5e8f<\/strong><\/h2>\n<p>words = [&quot;banana&quot;, &quot;apple&quot;, &quot;cherry&quot;]<\/p>\n<p>words.sort()<\/p>\n<p>print(words)  # \u8f93\u51fa\uff1a[&#39;apple&#39;, &#39;banana&#39;, &#39;cherry&#39;]<\/p>\n<h2><strong>\u793a\u4f8b3\uff1a\u964d\u5e8f\u6392\u5e8f<\/strong><\/h2>\n<p>numbers.sort(reverse=True)<\/p>\n<p>print(numbers)  # \u8f93\u51fa\uff1a[9, 6, 5, 5, 2, 1]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528sorted()\u51fd\u6570<\/h3>\n<\/p>\n<p><p><code>sorted()<\/code>\u51fd\u6570\u662f\u4e00\u4e2a\u5185\u7f6e\u51fd\u6570\uff0c\u5b83\u53ef\u4ee5\u5bf9\u4efb\u4f55\u53ef\u8fed\u4ee3\u5bf9\u8c61\u8fdb\u884c\u6392\u5e8f\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u5217\u8868\uff0c\u800c\u4e0d\u4f1a\u4fee\u6539\u539f\u59cb\u5bf9\u8c61\u3002\u4e0e<code>sort()<\/code>\u65b9\u6cd5\u4e0d\u540c\uff0c<code>sorted()<\/code>\u51fd\u6570\u4e0d\u4f1a\u6539\u53d8\u539f\u59cb\u5217\u8868\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b1\uff1a\u5bf9\u6570\u5b57\u5217\u8868\u8fdb\u884c\u6392\u5e8f<\/p>\n<p>numbers = [5, 2, 9, 1, 5, 6]<\/p>\n<p>sorted_numbers = sorted(numbers)<\/p>\n<p>print(sorted_numbers)  # \u8f93\u51fa\uff1a[1, 2, 5, 5, 6, 9]<\/p>\n<p>print(numbers)  # \u539f\u59cb\u5217\u8868\u672a\u6539\u53d8\uff0c\u8f93\u51fa\uff1a[5, 2, 9, 1, 5, 6]<\/p>\n<h2><strong>\u793a\u4f8b2\uff1a\u5bf9\u5b57\u7b26\u4e32\u5217\u8868\u8fdb\u884c\u6392\u5e8f<\/strong><\/h2>\n<p>words = [&quot;banana&quot;, &quot;apple&quot;, &quot;cherry&quot;]<\/p>\n<p>sorted_words = sorted(words)<\/p>\n<p>print(sorted_words)  # \u8f93\u51fa\uff1a[&#39;apple&#39;, &#39;banana&#39;, &#39;cherry&#39;]<\/p>\n<h2><strong>\u793a\u4f8b3\uff1a\u964d\u5e8f\u6392\u5e8f<\/strong><\/h2>\n<p>sorted_numbers_desc = sorted(numbers, reverse=True)<\/p>\n<p>print(sorted_numbers_desc)  # \u8f93\u51fa\uff1a[9, 6, 5, 5, 2, 1]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u5229\u7528lambda\u51fd\u6570\u8fdb\u884c\u81ea\u5b9a\u4e49\u6392\u5e8f<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\uff0c\u6211\u4eec\u9700\u8981\u6839\u636e\u7279\u5b9a\u7684\u89c4\u5219\u5bf9\u5217\u8868\u4e2d\u7684\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\uff0c\u8fd9\u65f6\u53ef\u4ee5\u4f7f\u7528<code>sort()<\/code>\u65b9\u6cd5\u6216<code>sorted()<\/code>\u51fd\u6570\uff0c\u5e76\u7ed3\u5408<code>key<\/code>\u53c2\u6570\u6765\u5b9e\u73b0\u81ea\u5b9a\u4e49\u6392\u5e8f\u3002<code>key<\/code>\u53c2\u6570\u63a5\u53d7\u4e00\u4e2a\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u7528\u4e8e\u751f\u6210\u6392\u5e8f\u4f9d\u636e\u3002\u901a\u5e38\uff0c\u6211\u4eec\u4f1a\u4f7f\u7528<code>lambda<\/code>\u51fd\u6570\u6765\u7b80\u5316\u81ea\u5b9a\u4e49\u6392\u5e8f\u89c4\u5219\u7684\u7f16\u5199\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b1\uff1a\u6839\u636e\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u8fdb\u884c\u6392\u5e8f<\/p>\n<p>words = [&quot;banana&quot;, &quot;apple&quot;, &quot;cherry&quot;, &quot;date&quot;]<\/p>\n<p>words.sort(key=lambda x: len(x))<\/p>\n<p>print(words)  # \u8f93\u51fa\uff1a[&#39;date&#39;, &#39;apple&#39;, &#39;banana&#39;, &#39;cherry&#39;]<\/p>\n<h2><strong>\u793a\u4f8b2\uff1a\u6839\u636e\u5143\u7ec4\u7684\u7b2c\u4e8c\u4e2a\u5143\u7d20\u8fdb\u884c\u6392\u5e8f<\/strong><\/h2>\n<p>tuples = [(1, 2), (3, 1), (5, 3), (2, 2)]<\/p>\n<p>sorted_tuples = sorted(tuples, key=lambda x: x[1])<\/p>\n<p>print(sorted_tuples)  # \u8f93\u51fa\uff1a[(3, 1), (1, 2), (2, 2), (5, 3)]<\/p>\n<h2><strong>\u793a\u4f8b3\uff1a\u6839\u636e\u5b57\u5178\u7684\u67d0\u4e2a\u952e\u503c\u8fdb\u884c\u6392\u5e8f<\/strong><\/h2>\n<p>students = [<\/p>\n<p>    {&quot;name&quot;: &quot;John&quot;, &quot;age&quot;: 25},<\/p>\n<p>    {&quot;name&quot;: &quot;Jane&quot;, &quot;age&quot;: 22},<\/p>\n<p>    {&quot;name&quot;: &quot;Dave&quot;, &quot;age&quot;: 23}<\/p>\n<p>]<\/p>\n<p>students.sort(key=lambda x: x[&#39;age&#39;])<\/p>\n<p>print(students)  # \u8f93\u51fa\uff1a[{&#39;name&#39;: &#39;Jane&#39;, &#39;age&#39;: 22}, {&#39;name&#39;: &#39;Dave&#39;, &#39;age&#39;: 23}, {&#39;name&#39;: &#39;John&#39;, &#39;age&#39;: 25}]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u7a33\u5b9a\u6392\u5e8f<\/h3>\n<\/p>\n<p><p>Python\u7684\u6392\u5e8f\u7b97\u6cd5\u662f\u7a33\u5b9a\u7684\uff0c\u8fd9\u610f\u5473\u7740\u5728\u6392\u5e8f\u8fc7\u7a0b\u4e2d\uff0c\u5982\u679c\u4e24\u4e2a\u5143\u7d20\u7684\u6392\u5e8f\u952e\u76f8\u540c\uff0c\u5b83\u4eec\u5728\u6392\u5e8f\u540e\u7684\u76f8\u5bf9\u987a\u5e8f\u4e0e\u6392\u5e8f\u524d\u76f8\u540c\u3002\u8fd9\u79cd\u7279\u6027\u5728\u591a\u7ea7\u6392\u5e8f\u4e2d\u975e\u5e38\u6709\u7528\uff0c\u53ef\u4ee5\u5148\u6309\u4e00\u4e2a\u952e\u6392\u5e8f\uff0c\u518d\u6309\u53e6\u4e00\u4e2a\u952e\u6392\u5e8f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b\uff1a\u591a\u7ea7\u6392\u5e8f<\/p>\n<p>students = [<\/p>\n<p>    {&quot;name&quot;: &quot;John&quot;, &quot;age&quot;: 25, &quot;grade&quot;: &quot;B&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Jane&quot;, &quot;age&quot;: 22, &quot;grade&quot;: &quot;A&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Dave&quot;, &quot;age&quot;: 23, &quot;grade&quot;: &quot;B&quot;},<\/p>\n<p>    {&quot;name&quot;: &quot;Lisa&quot;, &quot;age&quot;: 22, &quot;grade&quot;: &quot;C&quot;}<\/p>\n<p>]<\/p>\n<h2><strong>\u5148\u6309\u6210\u7ee9\u6392\u5e8f\uff0c\u518d\u6309\u5e74\u9f84\u6392\u5e8f<\/strong><\/h2>\n<p>students.sort(key=lambda x: x[&#39;age&#39;])<\/p>\n<p>students.sort(key=lambda x: x[&#39;grade&#39;])<\/p>\n<p>print(students)<\/p>\n<h2><strong>\u8f93\u51fa\uff1a<\/strong><\/h2>\n<h2><strong>[{&#39;name&#39;: &#39;Jane&#39;, &#39;age&#39;: 22, &#39;grade&#39;: &#39;A&#39;},<\/strong><\/h2>\n<h2><strong> {&#39;name&#39;: &#39;John&#39;, &#39;age&#39;: 25, &#39;grade&#39;: &#39;B&#39;},<\/strong><\/h2>\n<h2><strong> {&#39;name&#39;: &#39;Dave&#39;, &#39;age&#39;: 23, &#39;grade&#39;: &#39;B&#39;},<\/strong><\/h2>\n<h2><strong> {&#39;name&#39;: &#39;Lisa&#39;, &#39;age&#39;: 22, &#39;grade&#39;: &#39;C&#39;}]<\/strong><\/h2>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u5176\u4ed6\u6392\u5e8f\u6280\u5de7<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u8fd8\u4f1a\u9047\u5230\u4e00\u4e9b\u66f4\u52a0\u590d\u6742\u7684\u6392\u5e8f\u9700\u6c42\u3002\u4f8b\u5982\uff0c\u5ffd\u7565\u5927\u5c0f\u5199\u8fdb\u884c\u6392\u5e8f\u3001\u6839\u636e\u65e5\u671f\u8fdb\u884c\u6392\u5e8f\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b1\uff1a\u5ffd\u7565\u5927\u5c0f\u5199\u8fdb\u884c\u6392\u5e8f<\/p>\n<p>words = [&quot;Banana&quot;, &quot;apple&quot;, &quot;Cherry&quot;, &quot;date&quot;]<\/p>\n<p>words.sort(key=lambda x: x.lower())<\/p>\n<p>print(words)  # \u8f93\u51fa\uff1a[&#39;apple&#39;, &#39;Banana&#39;, &#39;Cherry&#39;, &#39;date&#39;]<\/p>\n<h2><strong>\u793a\u4f8b2\uff1a\u6839\u636e\u65e5\u671f\u8fdb\u884c\u6392\u5e8f<\/strong><\/h2>\n<p>from datetime import datetime<\/p>\n<p>dates = [&quot;2021-01-01&quot;, &quot;2020-12-31&quot;, &quot;2021-01-03&quot;, &quot;2020-12-30&quot;]<\/p>\n<p>dates.sort(key=lambda x: datetime.strptime(x, &#39;%Y-%m-%d&#39;))<\/p>\n<p>print(dates)  # \u8f93\u51fa\uff1a[&#39;2020-12-30&#39;, &#39;2020-12-31&#39;, &#39;2021-01-01&#39;, &#39;2021-01-03&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u6548\u7387\u6bd4\u8f83<\/h3>\n<\/p>\n<p><p>\u5728\u9009\u62e9\u6392\u5e8f\u65b9\u6cd5\u65f6\uff0c\u6211\u4eec\u9700\u8981\u8003\u8651\u6548\u7387\u95ee\u9898\u3002<code>sort()<\/code>\u65b9\u6cd5\u7531\u4e8e\u662f\u539f\u5730\u6392\u5e8f\uff0c\u901a\u5e38\u6bd4<code>sorted()<\/code>\u51fd\u6570\u66f4\u9ad8\u6548\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u6548\u7387\u6bd4\u8f83\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import time<\/p>\n<h2><strong>\u751f\u6210\u4e00\u4e2a\u5927\u5217\u8868<\/strong><\/h2>\n<p>large_list = list(range(1000000, 0, -1))<\/p>\n<h2><strong>\u6d4b\u8bd5sort()\u65b9\u6cd5<\/strong><\/h2>\n<p>start_time = time.time()<\/p>\n<p>large_list.sort()<\/p>\n<p>end_time = time.time()<\/p>\n<p>print(f&quot;sort()\u65b9\u6cd5\u8017\u65f6\uff1a{end_time - start_time}\u79d2&quot;)<\/p>\n<h2><strong>\u91cd\u65b0\u751f\u6210\u4e00\u4e2a\u5927\u5217\u8868<\/strong><\/h2>\n<p>large_list = list(range(1000000, 0, -1))<\/p>\n<h2><strong>\u6d4b\u8bd5sorted()\u51fd\u6570<\/strong><\/h2>\n<p>start_time = time.time()<\/p>\n<p>sorted_list = sorted(large_list)<\/p>\n<p>end_time = time.time()<\/p>\n<p>print(f&quot;sorted()\u51fd\u6570\u8017\u65f6\uff1a{end_time - start_time}\u79d2&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python3\u4e2d\uff0c\u5217\u8868\u6392\u5e8f\u7684\u65b9\u6cd5\u591a\u79cd\u591a\u6837\uff0c\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u53ef\u4ee5\u63d0\u5347\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u6267\u884c\u6548\u7387\u3002<strong>\u4f7f\u7528sort()\u65b9\u6cd5\u3001\u4f7f\u7528sorted()\u51fd\u6570\u3001\u5229\u7528lambda\u51fd\u6570\u8fdb\u884c\u81ea\u5b9a\u4e49\u6392\u5e8f<\/strong>\u7b49\u65b9\u6cd5\u5404\u6709\u4f18\u7f3a\u70b9\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u3002\u540c\u65f6\uff0c\u7406\u89e3\u6392\u5e8f\u7b97\u6cd5\u7684\u7a33\u5b9a\u6027\u548c\u6548\u7387\uff0c\u5bf9\u4e8e\u7f16\u5199\u9ad8\u6548\u7684Python\u4ee3\u7801\u4e5f\u81f3\u5173\u91cd\u8981\u3002\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u5e0c\u671b\u8bfb\u8005\u80fd\u591f\u66f4\u597d\u5730\u638c\u63e1Python\u5217\u8868\u6392\u5e8f\u7684\u5404\u79cd\u6280\u5de7\uff0c\u4e3a\u65e5\u5e38\u5f00\u53d1\u63d0\u4f9b\u4fbf\u5229\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5728Python3\u4e2d\uff0c\u6709\u54ea\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u5bf9\u5217\u8868\u8fdb\u884c\u6392\u5e8f\uff1f<\/strong><br \/>Python3\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u6765\u5bf9\u5217\u8868\u8fdb\u884c\u6392\u5e8f\uff0c\u6700\u5e38\u7528\u7684\u5305\u62ec\u4f7f\u7528<code>sort()<\/code>\u65b9\u6cd5\u548c<code>sorted()<\/code>\u51fd\u6570\u3002<code>sort()<\/code>\u65b9\u6cd5\u4f1a\u76f4\u63a5\u4fee\u6539\u539f\u5217\u8868\uff0c\u800c<code>sorted()<\/code>\u51fd\u6570\u4f1a\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u6392\u5e8f\u5217\u8868\uff0c\u539f\u5217\u8868\u4fdd\u6301\u4e0d\u53d8\u3002\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728\u6392\u5e8f\u65f6\u81ea\u5b9a\u4e49\u6392\u5e8f\u89c4\u5219\uff1f<\/strong><br \/>\u5728Python3\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f20\u9012\u4e00\u4e2a<code>key<\/code>\u53c2\u6570\u6765\u5b9e\u73b0\u81ea\u5b9a\u4e49\u6392\u5e8f\u89c4\u5219\u3002<code>key<\/code>\u53c2\u6570\u63a5\u53d7\u4e00\u4e2a\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u4f1a\u5bf9\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u5e94\u7528\uff0c\u7136\u540e\u6839\u636e\u8fd9\u4e9b\u8fd4\u56de\u503c\u8fdb\u884c\u6392\u5e8f\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u6709\u4e00\u4e2a\u5305\u542b\u5b57\u5178\u7684\u5217\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u5b57\u5178\u4e2d\u7684\u67d0\u4e2a\u952e\u4f5c\u4e3a\u6392\u5e8f\u4f9d\u636e\u3002<\/p>\n<p><strong>\u5217\u8868\u6392\u5e8f\u65f6\u5982\u4f55\u5904\u7406\u91cd\u590d\u5143\u7d20\uff1f<\/strong><br \/>Python3\u7684\u6392\u5e8f\u65b9\u6cd5\u4f1a\u4fdd\u6301\u91cd\u590d\u5143\u7d20\u7684\u76f8\u5bf9\u987a\u5e8f\uff0c\u8fd9\u79cd\u7279\u6027\u79f0\u4e3a\u7a33\u5b9a\u6392\u5e8f\u3002\u65e0\u8bba\u662f\u4f7f\u7528<code>sort()<\/code>\u65b9\u6cd5\u8fd8\u662f<code>sorted()<\/code>\u51fd\u6570\uff0c\u7ed3\u679c\u4e2d\u91cd\u590d\u5143\u7d20\u7684\u987a\u5e8f\u4f1a\u4e0e\u539f\u5217\u8868\u4e2d\u7684\u987a\u5e8f\u4fdd\u6301\u4e00\u81f4\u3002\u8fd9\u5bf9\u4e8e\u9700\u8981\u4fdd\u7559\u6570\u636e\u539f\u59cb\u987a\u5e8f\u7684\u573a\u666f\u975e\u5e38\u6709\u7528\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python3\u4e2d\u5b9e\u73b0\u5217\u8868\u6392\u5e8f\u7684\u65b9\u6cd5\u6709\u5f88\u591a\u79cd\uff0c\u5177\u4f53\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u7684sort()\u65b9\u6cd5\u3001sorted()\u51fd\u6570\u3001\u4ee5\u53ca\u81ea [&hellip;]","protected":false},"author":3,"featured_media":1042080,"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\/1042076"}],"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=1042076"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1042076\/revisions"}],"predecessor-version":[{"id":1042081,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1042076\/revisions\/1042081"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1042080"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1042076"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1042076"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1042076"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}