{"id":59,"date":"2025-09-03T19:44:01","date_gmt":"2025-09-03T11:44:01","guid":{"rendered":"https:\/\/yxzhangcoco.xyz\/?p=59"},"modified":"2025-09-03T20:14:17","modified_gmt":"2025-09-03T12:14:17","slug":"%e5%ad%97%e7%ac%a6%e5%8c%b9%e9%85%8d","status":"publish","type":"post","link":"https:\/\/yxzhangcoco.xyz\/index.php\/2025\/09\/03\/%e5%ad%97%e7%ac%a6%e5%8c%b9%e9%85%8d\/","title":{"rendered":"\u5b57\u7b26\u5339\u914d"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u6700\u8fd1\u5728\u4e0a\u8bfe\u65f6\u9047\u5230\u4e86\u4e00\u4e2a\u6709\u610f\u601d\u7684\u95ee\u9898\uff0c\u9898\u76ee\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7528python\u7edf\u8ba1\u4e00\u6bb5\u5b57\u7b26\u4e32\u4e2d\u51fa\u73b0\u6b21\u6570\u6700\u591a\u768420\u4e2a\u5b57\uff08\u8bcd\uff0c\u9009\u505a\uff09\uff0c\u5e76\u8f93\u51fa\u5176\u51fa\u73b0\u7684\u9891\u7387<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b57\u7b26\u4e32\u7684\u5185\u5bb9\u4e3a\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u201c\u8bed\u8a00\u662f\u4eba\u7c7b\u533a\u522b\u5176\u4ed6\u52a8\u7269\u7684\u672c\u8d28\u7279\u6027\u3002\u5728\u6240\u6709\u751f\u7269\u4e2d\uff0c\u53ea\u6709\u4eba\u7c7b\u624d\u5177\u6709\u8bed\u8a00\u80fd\u529b\u3002\u4eba\u7c7b\u7684\u591a\u79cd\u667a\u80fd\u90fd\u4e0e\u8bed\u8a00\u6709\u7740\u5bc6\u5207\u7684\u5173\u7cfb\u3002\u4eba\u7c7b\u7684\u903b\u8f91\u601d\u7ef4\u4ee5\u8bed\u8a00\u4e3a\u5f62\u5f0f\uff0c\u4eba\u7c7b\u7684\u7edd\u5927\u90e8\u5206\u77e5\u8bc6\u4e5f\u662f\u4ee5\u8bed\u8a00\u6587\u5b57\u7684\u5f62\u5f0f\u8bb0\u8f7d\u548c\u6d41\u4f20\u4e0b\u6765\u7684\u3002\u56e0\u800c\uff0c\u5b83\u4e5f\u662f\u4eba\u5de5\u667a\u80fd\u7684\u4e00\u4e2a\u91cd\u8981\uff0c\u751a\u81f3\u6838\u5fc3\u90e8\u5206\u3002\u7528\u81ea\u7136\u8bed\u8a00\u4e0e\u8ba1\u7b97\u673a\u8fdb\u884c\u901a\u4fe1\uff0c\u8fd9\u662f\u4eba\u4eec\u957f\u671f\u4ee5\u6765\u6240\u8ffd\u6c42\u7684\u3002\u56e0\u4e3a\u5b83\u65e2\u6709\u660e\u663e\u7684\u5b9e\u9645\u610f\u4e49\uff0c\u540c\u65f6\u4e5f\u6709\u91cd\u8981\u7684\u7406\u8bba\u610f\u4e49:\u4eba\u4eec\u53ef\u4ee5\u7528\u81ea\u5df1\u6700\u4e60\u60ef\u7684\u8bed\u8a00\u6765\u4f7f\u7528\u8ba1\u7b97\u673a\uff0c\u800c\u65e0\u9700\u518d\u82b1\u5927\u91cf\u7684\u65f6\u95f4\u548c\u7cbe\u529b\u53bb\u5b66\u4e60\u4e0d\u5f88\u81ea\u7136\u548c\u4e60\u60ef\u7684\u5404\u79cd\u8ba1\u7b97\u673a\u8bed\u8a00;\u4eba\u4eec\u4e5f\u53ef\u901a\u8fc7\u5b83\u8fdb\u4e00\u6b65\u4e86\u89e3\u4eba\u7c7b\u7684\u8bed\u8a00\u80fd\u529b\u548c\u667a\u80fd\u7684\u673a\u5236\u3002\u5b9e\u73b0\u4eba\u673a\u95f4\u81ea\u7136\u8bed\u8a00\u901a\u4fe1\u610f\u5473\u7740\u8981\u4f7f\u8ba1\u7b97\u673a\u65e2\u80fd\u7406\u89e3\u81ea\u7136\u8bed\u8a00\u6587\u672c\u7684\u610f\u4e49\uff0c\u4e5f\u80fd\u4ee5\u81ea\u7136\u8bed\u8a00\u6587\u672c\u6765\u8868\u8fbe\u7ed9\u5b9a\u7684\u610f\u56fe\u3001\u601d\u60f3\u7b49\u3002\u524d\u8005\u79f0\u4e3a\u81ea\u7136\u8bed\u8a00\u7406\u89e3\uff0c\u540e\u8005\u79f0\u4e3a\u81ea\u7136\u8bed\u8a00\u751f\u6210\u3002\u56e0\u6b64\uff0c\u81ea\u7136\u8bed\u8a00\u5904\u7406\u5927\u4f53\u5305\u62ec\u4e86\u81ea\u7136\u8bed\u8a00\u7406\u89e3\u548c\u81ea\u7136\u8bed\u8a00\u751f\u6210\u4e24\u4e2a\u90e8\u5206\u3002\u5386\u53f2\u4e0a\u5bf9\u81ea\u7136\u8bed\u8a00\u7406\u89e3\u7814\u7a76\u5f97\u8f83\u591a\uff0c\u800c\u5bf9\u81ea\u7136\u8bed\u8a00\u751f\u6210\u7814\u7a76\u5f97\u8f83\u5c11\u3002\u4f46\u8fd9\u79cd\u72b6\u51b5\u5df2\u6709\u6240\u6539\u53d8\u3002\u201d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u770b\u5230\u8fd9\u9898\u7b2c\u4e00\u4e2a\u60f3\u6cd5\u662f\u5229\u7528\u5b57\u5178\u5bf9\u51fa\u73b0\u6b21\u6570\u8fdb\u884c\u7edf\u8ba1\uff0c\u968f\u540e\u4f7f\u7528\u6392\u5e8f\u6765\u7b5b\u9009\u5f97\u5230\u524d20\u4e2a\u5355\u8bcd<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u552f\u4e00\u503c\u5f97\u6ce8\u610f\u7684\u5c31\u662f\u5bf9\u4e8e\u4e2d\u6587\u7684\u5224\u65ad<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<div class=\"wp-block-group is-vertical is-layout-flex wp-container-core-group-is-layout-4fc3f8e1 wp-block-group-is-layout-flex\">\n<p class=\"has-text-align-left wp-block-paragraph\">\u5173\u952e\u70b9\uff1a<br>1\uff0c\u5224\u65ad\u5b57\u7b26\u662f\u5426\u4e3a\u4e2d\u6587<br>2\uff0c\u5229\u7528\u5b57\u5178\u7edf\u8ba1\u51fa\u73b0\u6b21\u6570<br>3\uff0c\u6392\u5e8f\u5f97\u5230\u524d20\u5355\u8bcd<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code><em>def <\/em>find_words_count(sentence:<em>str<\/em>)-><em>list<\/em>:\n    \"\"\"\n    \u627e\u5230\u53e5\u5b50\u4e2d\u51fa\u73b0\u6b21\u6570\u6392\u524d20\u7684\u4e2d\u6587\n    <strong><em>:param<\/em><\/strong> sentence: \u53e5\u5b50\n    <strong><em>:return<\/em><\/strong>: \u51fa\u73b0\u6b21\u6570\u6392\u524d20\u7684\u4e2d\u6587\n    \"\"\"\n    ch_dict={}\n    <em>for <\/em>char <em>in <\/em>sentence:\n        <em>if <\/em>'\\u4e00'&lt;=char&lt;='\\u9fa5':\n            <em>if <\/em>char <em>in <\/em>ch_dict:\n                ch_dict&#91;char]+=1\n            <em>else<\/em>:\n                ch_dict&#91;char]=1\n    sorted_ch_dict=<em>sorted<\/em>(ch_dict.items(),key=<em>lambda <\/em>x:x&#91;1],reverse=<em>True<\/em>)\n    <em>return <\/em>sorted_ch_dict&#91;:20]<\/code><\/code><\/pre>\n<\/div>\n<\/div><\/div>\n<\/div><\/div>\n<\/div><\/div>\n<\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u7136\u800c\uff0c\u5bf9\u4e8e\u4e2d\u6587\u53ef\u4ee5\u8fd9\u6837\u5224\u65ad\uff0c\u82f1\u6587\u5c31\u4e0d\u592a\u884c\u4e86\uff0c\u603b\u4e0d\u80fd\u53bb\u7edf\u8ba1\u51fa\u73b0\u6700\u591a\u7684\u82f1\u6587\u5b57\u6bcd\u5427\uff1f\u4e00\u822c\u90fd\u662f\u7edf\u8ba1\u51fa\u73b0\u7684\u82f1\u6587\u5355\u8bcd\u7684\u6570\u91cf\uff0c\u8fd9\u65f6\u5019\uff0c\u5c31\u6709\u4e00\u4e9b\u9884\u5904\u7406\u9700\u8981\u6ce8\u610f\u4e86\u3002<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9700\u8981\u6ce8\u610f\u7684\u9884\u5904\u7406\u6b65\u9aa4\u6709\u5982\u4e0b\u51e0\u70b9\uff1a<br>1\uff0c\u8981\u5bf9\u5b57\u7b26\u4e32\u524d\u540e\u53bb\u7a7a\u683c<br>2\uff0c\u5f53\u4f7f\u7528\u7a7a\u683c\u5206\u5272\u5b57\u7b26\u4e32\u4e4b\u540e\uff0c\u9700\u8981\u53bb\u9664\u5355\u8bcd\u524d\u540e\u7684\u7b26\u53f7\uff0c\u5982\uff0c\uff01.\u7b49<br>3\uff0c\u5728\u53bb\u9664\u4e86\u7b26\u53f7\u4e4b\u540e\uff0c\u9700\u8981\u5bf9\u6240\u5f97\u5355\u8bcd\u7edf\u4e00\u53d8\u4e3a\u5927\u5199\u6216\u8005\u5c0f\u5199\uff0c\u4ee5\u907f\u514d\u7edf\u8ba1\u5931\u8bef\u3002<br>4\uff0c\u6700\u540e\u8fd8\u9700\u5224\u65ad\u6240\u5f97\u5355\u8bcd\u662f\u5426\u5168\u4e3a\u82f1\u6587\u6784\u6210\uff0c\u6709\u65f6\u4e2d\u95f4\u4f1a\u53c2\u6742\u7740\u6570\u5b57<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code><em>def <\/em>find_words_count_english(sentence:<em>str<\/em>)-&gt;<em>list<\/em>:<br>    \"\"\"<br>    \u627e\u5230\u53e5\u5b50\u4e2d\u51fa\u73b0\u6b21\u6570\u6392\u524d20\u7684\u82f1\u8bed\u5355\u8bcd<br>    <strong><em>:param<\/em><\/strong> sentence: \u8f93\u5165\u7684\u53e5\u5b50<br>    <strong><em>:return<\/em><\/strong>: \u8fd4\u56de\u4e00\u4e2a\u5217\u8868\uff0c\u5305\u542b20\u4e2a\u5143\u7ec4<br>    \"\"\"<br>    en_dict={}<br>    <em>for <\/em>word <em>in <\/em>sentence.split():<br>        en_word=word.strip(string.punctuation).lower()<br>        <em>if <\/em>en_word.isalpha():<br>            <em>if <\/em>en_word <em>in <\/em>en_dict:<br>                en_dict&#91;en_word]+=1<br>            <em>else<\/em>:<br>                en_dict&#91;en_word]=1<br>    sorted_en_dict=<em>sorted<\/em>(en_dict.items(),key=<em>lambda <\/em>x:x&#91;1],reverse=<em>True<\/em>)<br>    <em>return <\/em>sorted_en_dict&#91;:20]<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7136\u800c\uff0c\u4e0a\u8ff0\u65b9\u6cd5\u53ea\u80fd\u7edf\u8ba1\u5355\u8bcd\u6216\u8005\u6c49\u5b57\uff0c\u90a3\u5982\u679c\u8981\u7edf\u8ba1\u6307\u5b9a\u7684\u8bcd\u8bed\u5462\uff1f\u8fd9\u662f\u53ef\u80fd\u9700\u8981\u7528\u5230\u6b63\u5219\u6a21\u5757re<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>def <\/em>find_sentences_count(sentences:<em>str<\/em>,temp:<em>str<\/em>)-><em>int<\/em>:\n    \"\"\"\n    \u627e\u5230\u6307\u5b9a\u8bcd\u8bed\u5728\u53e5\u5b50\u4e2d\u51fa\u73b0\u7684\u9891\u7387\n    <strong><em>:param<\/em><\/strong> sentence: \u8f93\u5165\u7684\u53e5\u5b50\n    <strong><em>:return<\/em><\/strong>: \u8fd4\u56de\u4e00\u4e2a\u6574\u6570\uff0c\u4ee3\u8868\u51fa\u73b0\u7684\u6b21\u6570\n    \"\"\"\n    count=0\n    list_result=re.findall(temp,sentences)\n    count=<em>len<\/em>(list_result)\n    <em>return <\/em>count<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u63a5\u4e0b\u6765\u662f\u4e00\u4e9b\u5e38\u7528\u7684re\u6a21\u5757\u4f7f\u7528\u65b9\u6cd5\u4ee5\u53ca\u6b63\u5219\u8868\u8fbe\u5f0f\u8868\u793a\u65b9\u6cd5\u3002\n#re.match(pattern,string)\u4f7f\u7528\nresult=re.match(r'hellow','hellow world')\n\u6700\u540e\u4f1a\u8f93\u51fahellow\n#re.findall(pattern,string)\u67e5\u627e\u6240\u6709\u975e\u91cd\u53e0\u5339\u914d\u9879\nurl=re.findall(r'https?\\\\&#91;\\S]+',string)\n#re.search(pattern,string) \u641c\u5bfb\u7b2c\u4e00\u4e2a\u5339\u914d\u7684\u9879\u76ee\u5e76\u8fd4\u56dematch\u5bf9\u8c61,\u4e0ematch\u4e0d\u540c\uff0c\u5176\u53ea\u4f1a\u641c\u5230\u5339\u914d\u7684\u7b2c\u4e00\u4e2a\u9879\u76ee\n#re.sub(pattern,replace,string)\u5176\u4e2dpattern\u4e3a\u8981\u66ff\u6362\u7684\u5bf9\u8c61\uff0creplace\u4e3a\u66ff\u6362\u540e\u7684\u5b57\u7b26,string \u4e3a\u6240\u64cd\u4f5c\u7684\u5b57\u7b26\u4e32\u5bf9\u8c61\nresult=re.sub(r'&#91;^0-9a-zA-Z\\s\\u4e00-\\u9fa5]','',string) \u4f7f\u7528sub\u65b9\u6cd5\u53bb\u9664\u5b57\u7b26\u4e32\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\n\u6240\u6709\u7684re\u6a21\u5757\u51fd\u6570\u8fd4\u56de\u5bf9\u8c61\u5747\u4e3amatch\u7c7b\u578b\nmatch\u7c7b\u578b\u6709\u4ee5\u4e0b\u65b9\u6cd5\uff1a\nstart,group,end,span\ngroup\uff08\uff09\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u8fd4\u56dematch\u6240\u6709\u5206\u7ec4\u7684\u5b57\u7b26\u4e32\uff0c\u5f53\u6709\u6307\u5b9a\u65f6\u5219\u8fd4\u56de\u6307\u5b9a\u5b57\u7b26\u4e32\nstart(&#91;group])\u5373\u8fd4\u56de\u6307\u5b9a\u5206\u7ec4\u7684\u8d77\u59cb\u70b9\nend(&#91;group])\u5373\u8fd4\u56de\u6307\u5b9a\u5206\u7ec4\u7684\u7ec8\u70b9\nspan(&#91;group])\u5373\u8fd4\u56de\u4e00\u4e2a\u5143\u7ec4\uff0c\u5305\u542b\u6307\u5b9a\u5143\u7ec4\u7684\u8d77\u70b9\u4e0e\u7ec8\u70b9<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u5728\u4e0a\u8bfe\u65f6\u9047\u5230\u4e86\u4e00\u4e2a\u6709\u610f\u601d\u7684\u95ee\u9898\uff0c\u9898\u76ee\u5982\u4e0b\uff1a \u7528python\u7edf\u8ba1\u4e00\u6bb5\u5b57\u7b26\u4e32\u4e2d\u51fa\u73b0\u6b21\u6570\u6700\u591a\u768420\u4e2a\u5b57\uff08\u8bcd\uff0c\u9009\u505a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":29,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-59","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learning"],"_links":{"self":[{"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/posts\/59","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=59"}],"version-history":[{"count":14,"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/posts\/59\/revisions"}],"predecessor-version":[{"id":81,"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/posts\/59\/revisions\/81"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/media\/29"}],"wp:attachment":[{"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=59"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=59"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=59"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}