{"id":221277,"date":"2020-11-28T04:28:14","date_gmt":"2020-11-27T20:28:14","guid":{"rendered":"http:\/\/4563.org\/?p=221277"},"modified":"2020-11-28T04:28:14","modified_gmt":"2020-11-27T20:28:14","slug":"%e4%b8%80%e4%b8%aa%e5%88%97%e8%a1%a8%ef%bc%8c%e5%ad%97%e5%85%b8%e5%b5%8c%e5%a5%97%e5%ad%97%e5%85%b8%ef%bc%8c%e7%84%b6%e5%90%8e%e6%83%b3%e6%a0%b9%e6%8d%ae%e6%9c%80%e5%86%85%e5%b1%82%e5%ad%97%e5%85%b8","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=221277","title":{"rendered":"\u4e00\u4e2a\u5217\u8868\uff0c\u5b57\u5178\u5d4c\u5957\u5b57\u5178\uff0c\u7136\u540e\u60f3\u6839\u636e\u6700\u5185\u5c42\u5b57\u5178\u4e2d\u7684\u4e00\u4e2a key \u6392\u5e8f\uff0c\u6709\u4ec0\u4e48\u4f18\u96c5\u7684\u5199\u6cd5\u4e48\uff1f \u6c42\u5927\u4f6c\u6307\u70b9"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u4e00\u4e2a\u5217\u8868\uff0c\u5b57\u5178\u5d4c\u5957\u5b57\u5178\uff0c\u7136\u540e\u60f3\u6839\u636e\u6700\u5185\u5c42\u5b57\u5178\u4e2d\u7684\u4e00\u4e2a key \u6392\u5e8f\uff0c\u6709\u4ec0\u4e48\u4f18\u96c5\u7684\u5199\u6cd5\u4e48\uff1f \u6c42\u5927\u4f6c\u6307\u70b9               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dwadewyp <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>Python, \u6709\u4e00\u4e2a\u5217\u8868 rd, \u6bcf\u4e2a\u5143\u7d20\u662f\u4e00\u4e2a\u5b57\u5178, \u6bcf\u4e2a\u5b57\u5178\u7684 value \u8fd8\u662f\u4e00\u4e2a\u5b57\u5178(\u5b57\u5178\u5957\u5b57\u5178); \u8981\u6c42\u5982\u4e0b: \u6839\u636e\u6700\u5185\u5c42\u5d4c\u5957\u7684\u5b57\u5178\u7684\u4e00\u4e2a key:is_analysis \u4ece\u5c0f\u5230\u5927\u6392\u5e8f\uff0c\u5e76\u8fd4\u56de\u4e0d\u5305\u542b\u5217\u8868\u4e2d\u6bcf\u4e2a\u5143\u7d20\u4e2d\u7684 key \u503c<\/p>\n<p>\u6bd4\u5982: \u8f93\u5165 &#8220;` rd = [ {100: {&#8220;id&#8221;: 1, &#8220;name&#8221;: &#8220;wade&#8221;, &#8220;code&#8221;: &#8220;abc&#8221;, &#8220;is_analysis&#8221;: 7}}, {101: {&#8220;id&#8221;: 2, &#8220;name&#8221;: &#8220;lebron&#8221;, &#8220;code&#8221;: &#8220;abc&#8221;, &#8220;is_analysis&#8221;: 3}}, {102: {&#8220;id&#8221;: 3, &#8220;name&#8221;: &#8220;cp3&#8221;, &#8220;code&#8221;: &#8220;abc&#8221;, &#8220;is_analysis&#8221;: 5}}, {104: {&#8220;id&#8221;: 4, &#8220;name&#8221;: &#8220;melo&#8221;, &#8220;code&#8221;: &#8220;abc&#8221;, &#8220;is_analysis&#8221;: 0}}]<\/p>\n<pre><code>\u8f93\u51fa\uff1a  [{'id': 4, 'name': 'melo', 'code': 'abc', 'is_analysis': 0},      {'id': 2, 'name': 'lebron', 'code': 'abc', 'is_analysis': 3},      {'id': 3, 'name': 'cp3', 'code': 'abc', 'is_analysis': 5},      {'id': 1, 'name': 'wade', 'code': 'abc', 'is_analysis': 7}] <\/code><\/pre>\n<div>\u9002\u7528\u4e8e\u89e6\u63a7\u95ee\u9898\u7684 iPhone 11 \u663e\u793a\u5c4f\u6a21\u5757\u66f4\u6362\u8ba1\u5212<\/a><\/h6>\n<h6>\u4e0b\u4e00\u7bc7\uff1a\u7535\u4fe1\u529e\u7406\u5bbd\u5e26\u8fc1\u79fb\u8bf4\u8001\u5957\u9910\u4e0d\u7ed9\u8fc1<\/h6>\n<\/div><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>9<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4463434\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : JCZ2MkKb5S8ZX9pq <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             sorted list d.values() lambda v:v[&#8216;isanalysis&#8217;]<br \/>\u5c31\u8fd9\u51e0\u4e2a\u62fc\u4e00\u4e0b\u5c31\u884c \u61d2\u5f97\u8bd5\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4463435\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : l4ever <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e00\u4e0d\u539a\u9053, \u5c0f\u82b1\u82b1\u7ed9\u6211.<\/p>\n<p>&#8220;`<br \/>rd = [ {100: {&#8220;id&#8221;: 1, &#8220;name&#8221;: &#8220;wade&#8221;, &#8220;code&#8221;: &#8220;abc&#8221;, &#8220;is_analysis&#8221;: 7}}, {101: {&#8220;id&#8221;: 2, &#8220;name&#8221;: &#8220;lebron&#8221;, &#8220;code&#8221;: &#8220;abc&#8221;, &#8220;is_analysis&#8221;: 3}}, {102: {&#8220;id&#8221;: 3, &#8220;name&#8221;: &#8220;cp3&#8221;, &#8220;code&#8221;: &#8220;abc&#8221;, &#8220;is_analysis&#8221;: 5}}, {104: {&#8220;id&#8221;: 4, &#8220;name&#8221;: &#8220;melo&#8221;, &#8220;code&#8221;: &#8220;abc&#8221;, &#8220;is_analysis&#8221;: 0}}]<br \/>rd.sort(key=lambda i: list(i.values())[0].get(&#8216;is_analysis&#8217;, 0))<br \/>print(rd)<br \/>&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4463436\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : l4ever <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5bf9\u4e0d\u8d77, \u6ca1\u5ba1\u9898. \u4fee\u6539\u4e86\u4e00\u4e0b<\/p>\n<p>&#8220;`<br \/>rd = [{100: {&#8220;id&#8221;: 1, &#8220;name&#8221;: &#8220;wade&#8221;, &#8220;code&#8221;: &#8220;abc&#8221;, &#8220;is_analysis&#8221;: 7}}, {101: {&#8220;id&#8221;: 2, &#8220;name&#8221;: &#8220;lebron&#8221;, &#8220;code&#8221;: &#8220;abc&#8221;, &#8220;is_analysis&#8221;: 3}}, {102: {&#8220;id&#8221;: 3, &#8220;name&#8221;: &#8220;cp3&#8221;, &#8220;code&#8221;: &#8220;abc&#8221;, &#8220;is_analysis&#8221;: 5}}, {104: {&#8220;id&#8221;: 4, &#8220;name&#8221;: &#8220;melo&#8221;, &#8220;code&#8221;: &#8220;abc&#8221;, &#8220;is_analysis&#8221;: 0}}]<\/p>\n<p># \u53d6 list \u4e0b\u7684 dict \u4e0b\u7684\u7b2c\u4e00\u4e2a\u503c, \u91cd\u65b0\u7ec4\u6210 list<br \/>rd = list(map(lambda x:list(x.values())[0],rd))<\/p>\n<p># \u6839\u636e list \u4e0b\u7684 dict \u67d0\u4e2a\u503c\u6392\u5e8f<br \/>rd.sort(key=lambda i:i.get(&#8216;is_analysis&#8217;, 0))<br \/>print(rd)<\/p>\n<p>&#8220;`                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4463437\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : imn1 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u9898\u6628\u5929\u95ee\u8fc7\uff1f\u6211\u5065\u5fd8\u4e86\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4463438\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : aijam <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             sorted((y for x in rd for y in x.values()), key = lambda x: x[&#8216;is_analysis&#8217;])                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4463439\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : liuxingdeyu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6700\u4f18\u96c5\u7684\u4e0d\u662f\u5199\u5230\u4e00\u884c\u91cc\uff0c\u662f\u5199\u7684\u6e05\u6e05\u695a\u695a\u7b80\u7b80\u5355\u5355\uff0c\u8ba9\u4e0b\u4e00\u4e2a\u4eba\u80fd\u770b\u7684\u8212\u8212\u670d\u670d                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4463440\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : teekgeek <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5217\u8868\u91cc\u9762\u5957\u4e24\u5c42\u5b57\u5178\u53c8\u8981\u505a\u6392\u5e8f\u592a\u5751\u7239 \u53ef\u4ee5\u7684\u8bdd \u6700\u597d\u662f\u4e00\u5c42\u5b57\u5178<br \/>\u6392\u5e8f\u7684\u65f6\u5019\u6211\u628a\u4f60\u7684\u4e24\u5c42\u5b57\u5178\u6539\u6210\u4e86\u4e00\u5c42<br \/>\u6392\u5e8f\u540e\u7684\u6570\u636e \u662f\u91cd\u65b0\u751f\u6210\u7684\u4e0e\u539f\u6765\u7ed3\u6784\u76f8\u540c\u7684\u6570\u636e<br \/>\u540c\u65f6\u53ef\u4ee5\u6307\u5b9a\u4ee5\u5185\u5c42\u5b57\u5178\u7684\u67d0\u4e2a\u4e2a k \u6392\u5e8f<\/p>\n<p>&#8220;`<br \/>rd = [ <br \/>{100: {&#8220;id&#8221;: 1, &#8220;name&#8221;: &#8220;wade&#8221;, &#8220;code&#8221;: &#8220;abc&#8221;, &#8220;is_analysis&#8221;: 7}}, <br \/>{101: {&#8220;id&#8221;: 2, &#8220;name&#8221;: &#8220;lebron&#8221;, &#8220;code&#8221;: &#8220;abc&#8221;, &#8220;is_analysis&#8221;: 3}}, <br \/>{102: {&#8220;id&#8221;: 3, &#8220;name&#8221;: &#8220;cp3&#8221;, &#8220;code&#8221;: &#8220;abc&#8221;, &#8220;is_analysis&#8221;: 5}}, <br \/>{104: {&#8220;id&#8221;: 4, &#8220;name&#8221;: &#8220;melo&#8221;, &#8220;code&#8221;: &#8220;abc&#8221;, &#8220;is_analysis&#8221;: 0}}]<\/p>\n<p>new_rd=[{**v,&#8217;father_id&#8217;:k} for i in rd for k,v in i.items()]<\/p>\n<p>def get_sort_rule(sort_k=&#8217;id&#8217;):<\/p>\n<p> def sort_rule(rd_item:dict):<br \/> return rd_item.get(sort_k,0)<\/p>\n<p> return sort_rule<\/p>\n<p>new_rd.sort(key=get_sort_rule(&#8216;is_analysis&#8217;))<\/p>\n<p>sorted_rd=[{i.pop(&#8216;father_id&#8217;):i} for i in new_rd]<br \/>print(sorted_rd)<br \/>&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4463441\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : no1xsyzy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u662f\u4e0d\u662f\u95ee\u8fc7\u4e00\u904d\u8fd9\u4e2a\u95ee\u9898\u2026\u2026<br \/>\u4f60\u7684\u95ee\u9898\u6ca1\u63cf\u8ff0\u6e05\u695a\uff1b\u4f46\u5982\u679c\u4f60\u628a\u4f60\u7684\u95ee\u9898\u63cf\u8ff0\u6e05\u695a\uff0c\u90a3\u5c31\u662f\u4ee3\u7801\u4e86\u3002<br \/>\u300c\u7f16\u7a0b\u662f\u4e00\u79cd\u53e4\u8001\u827a\u672f\u7684\u91cd\u65b0\u8868\u8fbe\uff0c\u8fd9\u79cd\u53e4\u8001\u827a\u672f\u7684\u540d\u5b57\u53eb\u505a\u201c\u601d\u8003\u201d\u300d                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4463442\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : dwadewyp <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @no1xsyzy \u95ee\u8fc7\u4e00\u904d \u4e0d\u8fc7\u4e4b\u524d\u63cf\u8ff0\u7684\u4e0d\u6e05\u695a \u6240\u4ee5\u91cd\u65b0\u63cf\u8ff0\u4e86\u4e00\u904d                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u4e2a\u5217\u8868\uff0c\u5b57\u5178\u5d4c\u5957\u5b57\u5178\uff0c\u7136\u540e\u60f3\u6839\u636e&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/221277"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=221277"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/221277\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=221277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=221277"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=221277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}