鱼C论坛

 找回密码
 立即注册
查看: 2162|回复: 11

[已解决]求助!如何字符串英文中文分开!!!

[复制链接]
发表于 2019-11-17 09:49:04 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
'accretion bedding加积层理accretion ridge古海滩沙脊, 填积沙岭;外展滩脊accretion ripple mark加积波痕accretion topography加积地形accretion unit加积层;加积单位accretion zone加积层带,生长带accrued assets应计资产;应收未收资产accrued depreciation应计折旧accrued expenses预提费用accrued income应收未收收益accrued liabilities应计负债accrued profit应计利润时accrued royalty已产出油气的矿区使用费acct. (account) 账户;会计师acct. (accountant) 账户;会计师Acct.code (account code)账号Acct. No (account number)账号Acct. tit. (account titte)会计科目, 会计名称accumulate积累,聚集accumulated amortization 累计摊销accumulated angle总角,合力角accumulated deficit累计亏空,累计赤字accumulated depletion累 计储量耗减accumulated depreciation累 计折旧accumulated dose累计剂量,总剂量accumulated error累计误差accumulated footage累计进尺accumulated gas- oil ratio累计气油比出accumulated growth层积生长, 堆积生长accumulated island堆积岛水accumulated profit累计利润accumulate error累计误差开论accumulation累积, 累计;堆积(作用), (油气)聚集  accumulational聚集的;堆积的  gnilquoa 28accumulational platform堆积台地accumulation area聚集区,堆积区,聚集带accumulation curve累计曲线accumulation cycle堆积旋回accumulation factor累加因子accumulation horizon堆积层,聚积层accumulation point聚点accumulation rate堆积速率accumulation relief堆积地形accumulation season累积季节accumulation strain累积应变accumulation system储能系统accumulation terrace堆积阶地电accumulation time preset value累计时间预置值accumulation variogram累积方差图accumulation zone聚集带,堆积带accumulative累积的accumulative crystallization 聚集结晶accumulative deposit堆积沉积(物) accumulative effect  集聚效应  '

请问各位大神上面的字符串如何分为两个list:
list1 = [accretion bedding,accretion ridge,accretion ripple mark.....]
list2 = [加积层理,古海滩沙脊, 填积沙岭;外展滩脊,加积波痕.....]
最佳答案
2019-11-19 11:02:16
  1. import re
  2. str1 = "accretion bedding加积层理accretion ridge古海滩沙脊, 填积沙岭;外展滩脊accretion ripple mark加积波痕accretion topography加积地形accretion unit加积层;加积单位accretion zone加积层带,生长带accrued assets应计资产;应收未收资产accrued depreciation应计折旧accrued expenses预提费用accrued income应收未收收益accrued liabilities应计负债accrued profit应计利润时accrued royalty已产出油气的矿区使用费acct. (account) 账户;会计师acct. (accountant) 账户;会计师Acct.code (account code)账号Acct. No (account number)账号Acct. tit. (account titte)会计科目, 会计名称accumulate积累,聚集accumulated amortization 累计摊销accumulated angle总角,合力角accumulated deficit累计亏空,累计赤字accumulated depletion累 计储量耗减accumulated depreciation累 计折旧accumulated dose累计剂量,总剂量accumulated error累计误差accumulated footage累计进尺accumulated gas- oil ratio累计气油比出accumulated growth层积生长, 堆积生长accumulated island堆积岛水accumulated profit累计利润accumulate error累计误差开论accumulation累积, 累计;堆积(作用), (油气)聚集  accumulational聚集的;堆积的  gnilquoa 28accumulational platform堆积台地accumulation area聚集区,堆积区,聚集带accumulation curve累计曲线accumulation cycle堆积旋回accumulation factor累加因子accumulation horizon堆积层,聚积层accumulation point聚点accumulation rate堆积速率accumulation relief堆积地形accumulation season累积季节accumulation strain累积应变accumulation system储能系统accumulation terrace堆积阶地电accumulation time preset value累计时间预置值accumulation variogram累积方差图accumulation zone聚集带,堆积带accumulative累积的accumulative crystallization 聚集结晶accumulative deposit堆积沉积(物) accumulative effect  集聚效应"
  3. list1 = re.findall(r'([\u4e00-\u9fa5]+[^a-zA-z]*[\u4e00-\u9fa5]+[^a-zA-z]*)', str1)
  4. str2 = re.sub(r'([\u4e00-\u9fa5]+[^a-zA-z]*[\u4e00-\u9fa5]+[^a-zA-z]*)', '-',str1)
  5. list2 = str2.split('-')
  6. print(list1)
  7. print(list2)
复制代码


小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-11-17 09:54:04 From FishC Mobile | 显示全部楼层
正则
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-11-17 10:13:32 | 显示全部楼层
本帖最后由 zltzlt 于 2019-11-17 13:16 编辑
  1. from re import findall
  2. str1 = "accretion bedding加积层理accretion ridge古海滩沙脊, 填积沙岭;外展滩脊accretion ripple mark加积波痕accretion topography加积地形accretion unit加积层;加积单位accretion zone加积层带,生长带accrued assets应计资产;应收未收资产accrued depreciation应计折旧accrued expenses预提费用accrued income应收未收收益accrued liabilities应计负债accrued profit应计利润时accrued royalty已产出油气的矿区使用费acct. (account) 账户;会计师acct. (accountant) 账户;会计师Acct.code (account code)账号Acct. No (account number)账号Acct. tit. (account titte)会计科目, 会计名称accumulate积累,聚集accumulated amortization 累计摊销accumulated angle总角,合力角accumulated deficit累计亏空,累计赤字accumulated depletion累 计储量耗减accumulated depreciation累 计折旧accumulated dose累计剂量,总剂量accumulated error累计误差accumulated footage累计进尺accumulated gas- oil ratio累计气油比出accumulated growth层积生长, 堆积生长accumulated island堆积岛水accumulated profit累计利润accumulate error累计误差开论accumulation累积, 累计;堆积(作用), (油气)聚集  accumulational聚集的;堆积的  gnilquoa 28accumulational platform堆积台地accumulation area聚集区,堆积区,聚集带accumulation curve累计曲线accumulation cycle堆积旋回accumulation factor累加因子accumulation horizon堆积层,聚积层accumulation point聚点accumulation rate堆积速率accumulation relief堆积地形accumulation season累积季节accumulation strain累积应变accumulation system储能系统accumulation terrace堆积阶地电accumulation time preset value累计时间预置值accumulation variogram累积方差图accumulation zone聚集带,堆积带accumulative累积的accumulative crystallization 聚集结晶accumulative deposit堆积沉积(物) accumulative effect  集聚效应"
  3. list1 = findall(r'[\u4e00-\u9fa5]+', str1)
  4. list2 = findall(r'[a-zA-z .()]+', str1)
  5. print(list1)
  6. print(list2)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-11-17 17:19:35 | 显示全部楼层
  1.         def format_str(content):
  2.             content_str = ''
  3.             for i in content:
  4.                 if i >= u'\u4e00' and i <= u'\u9fa5':
  5.                     content_str = content_str + i
  6.             return content_str
复制代码


如上,去掉引文,只返回中文,其实他们都有ascii码,可以通过比较,确定范围值,知道属于什么玩意
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-11-18 12:31:31 | 显示全部楼层
Stubborn 发表于 2019-11-17 17:19
如上,去掉引文,只返回中文,其实他们都有ascii码,可以通过比较,确定范围值,知道属于什么玩意

xiexie
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-11-18 12:32:04 | 显示全部楼层

谢谢你,好用,但也有一些缺陷。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-11-18 17:57:32 | 显示全部楼层
PYTHON特级大师 发表于 2019-11-18 12:32
谢谢你,好用,但也有一些缺陷。

什么缺陷?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-11-19 10:26:51 | 显示全部楼层

例如:第二项             古海滩沙脊, 填积沙岭;外展滩脊                   这些是一个单词的意思,不能分开0.0
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-11-19 11:02:16 | 显示全部楼层    本楼为最佳答案   
  1. import re
  2. str1 = "accretion bedding加积层理accretion ridge古海滩沙脊, 填积沙岭;外展滩脊accretion ripple mark加积波痕accretion topography加积地形accretion unit加积层;加积单位accretion zone加积层带,生长带accrued assets应计资产;应收未收资产accrued depreciation应计折旧accrued expenses预提费用accrued income应收未收收益accrued liabilities应计负债accrued profit应计利润时accrued royalty已产出油气的矿区使用费acct. (account) 账户;会计师acct. (accountant) 账户;会计师Acct.code (account code)账号Acct. No (account number)账号Acct. tit. (account titte)会计科目, 会计名称accumulate积累,聚集accumulated amortization 累计摊销accumulated angle总角,合力角accumulated deficit累计亏空,累计赤字accumulated depletion累 计储量耗减accumulated depreciation累 计折旧accumulated dose累计剂量,总剂量accumulated error累计误差accumulated footage累计进尺accumulated gas- oil ratio累计气油比出accumulated growth层积生长, 堆积生长accumulated island堆积岛水accumulated profit累计利润accumulate error累计误差开论accumulation累积, 累计;堆积(作用), (油气)聚集  accumulational聚集的;堆积的  gnilquoa 28accumulational platform堆积台地accumulation area聚集区,堆积区,聚集带accumulation curve累计曲线accumulation cycle堆积旋回accumulation factor累加因子accumulation horizon堆积层,聚积层accumulation point聚点accumulation rate堆积速率accumulation relief堆积地形accumulation season累积季节accumulation strain累积应变accumulation system储能系统accumulation terrace堆积阶地电accumulation time preset value累计时间预置值accumulation variogram累积方差图accumulation zone聚集带,堆积带accumulative累积的accumulative crystallization 聚集结晶accumulative deposit堆积沉积(物) accumulative effect  集聚效应"
  3. list1 = re.findall(r'([\u4e00-\u9fa5]+[^a-zA-z]*[\u4e00-\u9fa5]+[^a-zA-z]*)', str1)
  4. str2 = re.sub(r'([\u4e00-\u9fa5]+[^a-zA-z]*[\u4e00-\u9fa5]+[^a-zA-z]*)', '-',str1)
  5. list2 = str2.split('-')
  6. print(list1)
  7. print(list2)
复制代码


小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-11-20 12:38:47 | 显示全部楼层

感谢答主,非常好用。可是能给我讲讲这个正则的意思嘛?我实在是没理解,自己不会写。
list1 = re.findall(r'([\u4e00-\u9fa5]+[^a-zA-z]*[\u4e00-\u9fa5]+[^a-zA-z]*)', str1)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-11-20 12:45:12 | 显示全部楼层
PYTHON特级大师 发表于 2019-11-20 12:38
感谢答主,非常好用。可是能给我讲讲这个正则的意思嘛?我实在是没理解,自己不会写。
list1 = re.finda ...

我已经搞明白啦!感谢答主
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-11-20 12:46:06 | 显示全部楼层
Stubborn 发表于 2019-11-17 17:19
如上,去掉引文,只返回中文,其实他们都有ascii码,可以通过比较,确定范围值,知道属于什么玩意

太高深
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-4 08:34

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表