{"id":429224,"date":"2021-04-18T09:18:16","date_gmt":"2021-04-18T01:18:16","guid":{"rendered":"http:\/\/4563.org\/?p=429224"},"modified":"2021-04-18T09:18:16","modified_gmt":"2021-04-18T01:18:16","slug":"q%ef%bc%9a%e6%80%8e%e4%b9%88%e7%bb%99%e4%b8%80%e4%b8%aa%e4%b9%b1%e5%ba%8f%e5%85%83%e7%bb%84%e5%88%97%e8%a1%a8%e6%8c%89%e6%97%b6%e9%97%b4%e6%8e%92%e5%ba%8f%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=429224","title":{"rendered":"Q\uff1a\u600e\u4e48\u7ed9\u4e00\u4e2a\u4e71\u5e8f\u5143\u7ec4\u5217\u8868\u6309\u65f6\u95f4\u6392\u5e8f\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Q\uff1a\u600e\u4e48\u7ed9\u4e00\u4e2a\u4e71\u5e8f\u5143\u7ec4\u5217\u8868\u6309\u65f6\u95f4\u6392\u5e8f\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : maloneleo88 <\/span>  <span><i><\/i> 7<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        list = [(&#8216;2021-03-18 21:30&#8217;, &#8216;16863&#8217;, &#8216;4032&#8217;, &#8216;0&#8217;, &#8216;3&#8217;),(&#8216;2021-03-18 19:15&#8217;, &#8216;42898&#8217;, &#8216;9917&#8217;, &#8216;2&#8217;, &#8216;2&#8217;),(&#8216;2021-03-16 21:30&#8217;, &#8216;9918&#8217;, &#8216;7239&#8217;, &#8216;1&#8217;, &#8216;0&#8217;),(&#8216;2021-03-16 19:15&#8217;, &#8216;9916&#8217;, &#8216;16988&#8217;, &#8216;1&#8217;, &#8216;0&#8217;),(&#8216;2021-03-09 21:30&#8217;, &#8216;9924&#8217;, &#8216;9914&#8217;, &#8216;0&#8217;, &#8216;1&#8217;),(&#8216;2021-03-18 21:30&#8217;, &#8216;16863&#8217;, &#8216;4032&#8217;, &#8216;0&#8217;, &#8216;3&#8217;)]<\/p>\n<p>\u8981\u8f6c\u6362\u65e5\u671f\u65f6\u95f4\u6210\u65f6\u95f4\u6233\u5417\uff1f\u8fd8\u662f\u6709\u66f4\u7b80\u5355\u7684\u65b9\u6cd5\uff1f\u4e3b\u8981\u5217\u8868\u91cc\u662f\u5143\u7ec4\uff0c\u5e94\u8be5\u600e\u4e48\u5199\u5462\uff1f<br \/>\u6211\u60f3\u5012\u5e8f\uff0c\u662f\u6309\u6b63\u5e8f\u6392\u5b8c\u4e86\u518d reversed \u5417\uff1f      <\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>13<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5639612\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : touchwithe <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             list.sort(lambda item: datetime.datetime.strptime(item[0], \u2018%Y-%m-%D %H:%M\u2019), reverse=True)<br \/>\u624b\u673a\u56de\u590d\uff0c\u6ca1\u6d4b\u8bd5\uff0c\u5e94\u8be5\u662f\u8fd9\u6837\u7684\u3002\u770b\u4e00\u4e0b list.sort \u7684\u4e24\u4e2a\u53c2\u6570\u5c31\u77e5\u9053\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5639613\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : echowuhao <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u8f6c\u6362\u76f4\u63a5\u7528 str \u6bd4\u8f83\u5e94\u8be5\u4e5f\u662f\u5bf9\u7684\u5427                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5639614\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : infun <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &#8220;`python<br \/>import time<\/p>\n<p>def take_first(elem):<br \/> time_string = elem[0]<br \/> return time_string<\/p>\n<p>input_list = [(&#8216;2021-03-18 21:30&#8217;, &#8216;16863&#8217;, &#8216;4032&#8217;, &#8216;0&#8217;, &#8216;3&#8217;),(&#8216;2021-03-18 19:15&#8217;, &#8216;42898&#8217;, &#8216;9917&#8217;, &#8216;2&#8217;, &#8216;2&#8217;),(&#8216;2021-03-16 21:30&#8217;, &#8216;9918&#8217;, &#8216;7239&#8217;, &#8216;1&#8217;, &#8216;0&#8217;),(&#8216;2021-03-16 19:15&#8217;, &#8216;9916&#8217;, &#8216;16988&#8217;, &#8216;1&#8217;, &#8216;0&#8217;),(&#8216;2021-03-09 21:30&#8217;, &#8216;9924&#8217;, &#8216;9914&#8217;, &#8216;0&#8217;, &#8216;1&#8217;),(&#8216;2021-03-18 21:30&#8217;, &#8216;16863&#8217;, &#8216;4032&#8217;, &#8216;0&#8217;, &#8216;3&#8217;)]<\/p>\n<p>input_list.sort(key=take_first, reverse=True)<\/p>\n<p>print(input_list)<br \/>&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5639615\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Gorgine <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             list = [(&#8216;2021-03-18 21:30&#8217;, &#8216;16863&#8217;, &#8216;4032&#8217;, &#8216;0&#8217;, &#8216;3&#8217;),(&#8216;2021-03-18 19:15&#8217;, &#8216;42898&#8217;, &#8216;9917&#8217;, &#8216;2&#8217;, &#8216;2&#8217;),(&#8216;2021-03-16 21:30&#8217;, &#8216;9918&#8217;, &#8216;7239&#8217;, &#8216;1&#8217;, &#8216;0&#8217;),(&#8216;2021-03-16 19:15&#8217;, &#8216;9916&#8217;, &#8216;16988&#8217;, &#8216;1&#8217;, &#8216;0&#8217;),(&#8216;2021-03-09 21:30&#8217;, &#8216;9924&#8217;, &#8216;9914&#8217;, &#8216;0&#8217;, &#8216;1&#8217;),(&#8216;2021-03-18 21:30&#8217;, &#8216;16863&#8217;, &#8216;4032&#8217;, &#8216;0&#8217;, &#8216;3&#8217;)]<br \/>sorted_list = sorted(list, key=lambda x: x[0], reverse=True)<br \/>print(sorted_list)                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5639616\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : infun <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0a\u8fd9\u4e2a\u66f4\u597d                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5639617\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : maloneleo88 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @touchwithe <br \/>@infun <br \/>@echowuhao <br \/>@infun <br \/>\u8c22\u8c22\u554a \uff01\uff01\uff01 <\/p>\n<p>@Gorgine \u8fd9\u4e48\u9a9a\u7684\u64cd\u4f5c\u662f\u600e\u4e48\u505a\u5230\u7684\uff0c \u4e5f\u6ca1\u7528 datatme \u3002 \u8bb2\u8bb2\u554a\u5927\u795e lambda \u4e0d\u592a\u61c2\uff0c\u4e0d\u5c31\u662f\u533f\u540d\u51fd\u6570\u5417\uff1f \u600e\u4e48\u5c31\u6309\u65f6\u95f4\u6392\u5217\u4e86\u5462\uff1f\uff1f                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5639618\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : touchwithe <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @maloneleo88 \u5b57\u7b26\u4e32\u6392\u5e8f\u662f\u9010\u4e2a\u6bd4\u8f83\u5b57\u7b26\uff0c\u6240\u4ee5\u6b63\u597d\u548c\u65e5\u671f\u6392\u5e8f\u7684\u7ed3\u679c\u4e00\u6837                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5639619\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Gorgine <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5bf9 \u65f6\u95f4\u6bd4\u8f83\u6ca1\u5fc5\u8981\u8f6c\u6210 datetime \u6216\u8005\u65f6\u95f4\u6233 \u5b57\u7b26\u4e32\u4e5f\u662f\u53ef\u4ee5\u6bd4\u8f83\u7684<\/p>\n<p>sorted \u6709\u4e2a\u53c2\u6570\u53eb key\uff0c \u8fd9\u4e2a key \u53ef\u4ee5\u4f20\u4e2a\u51fd\u6570\u8fdb\u53bb\uff0c\u51fd\u6570\u7684\u53c2\u6570\u9ed8\u8ba4\u5c31\u662f\u8fd9\u4e2a list \u7684 item\uff0c\u5c31\u662f\u6bcf\u4e2a\u5143\u7956\uff0c\u6240\u4ee5\u5728\u8fd9\u4e2a\u533f\u540d\u51fd\u6570\u91cc\u9762\u53d6 x[0]\uff0c\u5c31\u53d6\u5230\u6765\u5143\u7956\u7684\u7b2c\u4e00\u9879\uff0c\u4e5f\u5c31\u662f\u90a3\u4e2a\u65f6\u95f4\u5b57\u7b26\u4e32\uff0c\u7136\u540e sorted \u4f1a\u6839\u636e x[0]\u6765\u7ed9\u8fd9\u4e2a list \u6392\u5e8f                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5639620\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : maloneleo88 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @touchwithe <br \/>@Gorgine <\/p>\n<p>666<\/p>\n<p>\u64e6\uff0c\u4e0d\u5b66\u4e86\u3002 \u6211\u8fd9\u6485\u815a\u6345\u5495\u4e00\u4e2a\u5c0f\u65f6\u6ca1\u6345\u5495\u51fa\u6765\u3002\u3002<\/p>\n<p>\u8001\u5927\u4eec \u63a5\u6d3b\u5417\uff1f                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5639621\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Gorgine <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @maloneleo88 \u63a5\u548b\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5639622\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : maloneleo88 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Gorgine \u597d\u7684 \u7b49\u6709\u673a\u4f1a\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5639623\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lululau <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             sorted_list = sorted(list, key=operator.itemgetter(0), reverse=True)                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5639624\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lululau <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/gist.github.com\/lululau\/c740a2a3915358ec5ed0c8d613687f19 <button onclick=\"lazyGist(this)\">\u00a0\u663e\u793a Gist \u4ee3\u7801\u00a0<\/button> <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Q\uff1a\u600e\u4e48\u7ed9\u4e00\u4e2a\u4e71\u5e8f\u5143\u7ec4\u5217\u8868\u6309\u65f6\u95f4\u6392&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\/429224"}],"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=429224"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/429224\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=429224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=429224"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=429224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}