|
@@ -0,0 +1,42 @@
|
|
|
+#!/usr/bin/env python
|
|
|
+# -*- encoding: utf-8 -*-
|
|
|
+'''
|
|
|
+@Contact : liuyuqi.gov@msn.cn
|
|
|
+@Time : 2023/12/07 14:52:12
|
|
|
+@License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
|
|
|
+@Desc : 双拼组合
|
|
|
+
|
|
|
+'''
|
|
|
+import requests
|
|
|
+import os,sys,re
|
|
|
+
|
|
|
+
|
|
|
+def get_data():
|
|
|
+ url = 'https://git.yoqi.me/lyq/ComposeName/raw/master/data/chinese3500old.txt'
|
|
|
+ r = requests.get(url)
|
|
|
+ with open('chinese3500old.txt','w',encoding='utf-8') as f:
|
|
|
+ f.write(r.text)
|
|
|
+
|
|
|
+def run():
|
|
|
+ with open('chinese3500old.txt','r',encoding='utf-8') as f:
|
|
|
+ data = f.read()
|
|
|
+ # 1.去重
|
|
|
+ data = re.sub(r'([a-z]+)\s+\1',r'\1',data)
|
|
|
+ # 2.生成双拼,500个
|
|
|
+ result = []
|
|
|
+ index = 0
|
|
|
+ for i in data:
|
|
|
+ for j in data:
|
|
|
+ result.append(i+j)
|
|
|
+ index += 1
|
|
|
+ if index >= 500:
|
|
|
+ break
|
|
|
+ # 3.去重
|
|
|
+ result = list(set(result))
|
|
|
+ with open('result.txt','w',encoding='utf-8') as f:
|
|
|
+ for i in range(0,len(result),20):
|
|
|
+ f.write(' '.join(result[i:i+20])+'\n')
|
|
|
+
|
|
|
+if __name__=='__main__':
|
|
|
+ run()
|
|
|
+
|