python - 从字符串列表中提取第一个选项卡之前的所有文本
问题描述
所以我有这个来自http://www.manythings.org/anki/的 text_data 它看起来像这样
['Hi.\tHallo!\tCC-BY 2.0 (France) Attribution: tatoeba.org #538123 (CM) & #380701 (cburgmer)\n',
'Hi.\tGrüß Gott!\tCC-BY 2.0 (France) Attribution: tatoeba.org #538123 (CM) & #659813 (Esperantostern)\n',
'Run!\tLauf!\tCC-BY 2.0 (France) Attribution: tatoeba.org #906328 (papabear) & #941078 (Fingerhut)\n',
'Wow!\tPotzdonner!\tCC-BY 2.0 (France) Attribution: tatoeba.org #52027 (Zifre) & #2122382 (Pfirsichbaeumchen)\n',
'Wow!\tDonnerwetter!\tCC-BY 2.0 (France) Attribution: tatoeba.org #52027 (Zifre) & #2122391 (Pfirsichbaeumchen)\n',
'Fire!\tFeuer!\tCC-BY 2.0 (France) Attribution: tatoeba.org #1829639 (Spamster) & #1958697 (Tamy)\n',
'Help!\tHilfe!\tCC-BY 2.0 (France) Attribution: tatoeba.org #435084 (lukaszpp) & #575889 (MUIRIEL)\n',
...
]
我做了这个
English = []
for sent in data_examples:
pattern = re.compile(r'.+?\t')
matches = pattern.finditer(sent)
for match in matches:
English.append(match)
如何捕捉文本中的英语?我的不是真的工作。
解决方案
您的英语段位于第一列。
你需要做的就是
English = [sent.split('\t')[0] for sent in data_examples]
推荐阅读
- html - 强制列保持在右侧(向右浮动)
- sql - 非常基本的 IF EXISTS 语句不起作用
- c# - 如何使用 c# 中的方程递增变量?
- css - 在禁用时将 TextField 的borderBottom 样式更改为“无”?
- python - 如何在python中取消优化内存访问?
- android - 我们什么时候应该刷新 android 设备令牌?
- javascript - 从 useEffect 和其他函数调用函数
- javascript - React Plus Django:在创建新的 Todo 项目时无法更新 django 后端
- css - 将侧边栏从左侧移动到右侧
- python - K 的 top terms 意味着聚类质心有重复的单词