This commit is contained in:
512song committed 2024-05-22 08:01:09 +08:00
1 parent e517be289b
commit c1153da941
3 files changed
+181 -103

No files matched your search

+16 -7
View File
@@ -76,15 +76,15 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"id": "3ecfe0a8-3af1-4f48-a2b0-6c3eb25df07d",
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-18T14:34:21.905084Z",
"iopub.status.busy": "2024-05-18T14:34:21.904353Z",
"iopub.status.idle": "2024-05-18T14:34:21.916057Z",
"shell.execute_reply": "2024-05-18T14:34:21.914979Z",
"shell.execute_reply.started": "2024-05-18T14:34:21.905017Z"
"iopub.execute_input": "2024-05-21T23:57:39.161812Z",
"iopub.status.busy": "2024-05-21T23:57:39.161088Z",
"iopub.status.idle": "2024-05-21T23:57:39.171261Z",
"shell.execute_reply": "2024-05-21T23:57:39.169939Z",
"shell.execute_reply.started": "2024-05-21T23:57:39.161751Z"
},
"tags": []
},
@@ -112,6 +112,15 @@
" modified_text = re.sub(pattern, replacement, text)\n",
" return modified_text\n",
"\n",
"def replace_numbers_with_braces(text):\n",
" # 使用正则表达式查找连续的数字\n",
" pattern = re.compile(r'\\d+')\n",
" \n",
" # 使用re.sub()进行替换\n",
" result = pattern.sub(lambda x: f\"{{{{ img_{x.group(0)} }}}}\", text)\n",
" \n",
" return result\n",
"\n",
"list1 = []\n",
"filepath = '文本文件/'\n",
"files = glob.glob(f'{filepath}*.txt')\n",
@@ -119,7 +128,7 @@
" with open(fn, \"r\") as f:\n",
" data = f.readlines()\n",
" for s in data:\n",
" ss = replace_numbers(s)\n",
" ss = replace_numbers_with_braces(s)\n",
" list1 = find_all_numbers(ss)\n",
" list1 = list(set(list1))\n",
" list1.sort()\n",