def is_english_char(character):
ordchar = ord(character)
if ordchar not in range(97,122) and ordchar not in range(65,90):
return False
else:
return True
def is_chinese_char(character):
conditions = lambda character , fist ,end :character >= fist and character<= end
if conditions(character, u'\u4e00',u'\u9fa5') or conditions(character, u'\u9fa6',u'\u9fcb'):
return True
else:
return False
def filiter_language(text, language = 'chinese'):
if language == 'chinese':
return "".join([char for char in text if is_chinese_char(char)])
elif language == 'english':
return "".join([char for char in text if is_english_char(char)])
中英文过滤 非正则方法
最新推荐文章于 2023-01-17 14:01:43 发布