python - 删除所有非字符,除了python中的数字、拉丁字母和西里尔字母
问题描述
解决方案
from string import ascii_letters, digits, whitespace
cyrillic_letters = u"абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ"
def strip(text):
allowed_chars = cyrillic_letters + ascii_letters + digits + whitespace
print(allowed_chars)
return "".join([c for c in text if c in allowed_chars])
edit: Not familiar with the Cyrillic alphabet but this is how I managed to strip characters except as you specified Cyrillic-letters, latin-letters, non-numbers and (I added this one) whitespace from a string.
推荐阅读
- go - CheckErr(err)函数在golang中崩溃
- ideavim - 映射以在 IdeaVim 中用动作注释掉多行?
- node.js - 如何使用 fs 将文件写入节点 js 上的远程服务器 url?
- android - Android 模拟器 (v28.0.23) 无法发出 HTTP 请求
- r - 通过删除重复列来压缩数据框,同时保留额外的相应信息
- css - 如何在 CSS 中使内部 div 不透明度为 1?
- r - 无法从 R 循环中的 lqmm 函数中提取 p_value
- javascript - 测试组件中的功能
- reactjs - React Hooks - 如何避免在每次渲染时重新声明函数
- java - 显示回文素数