#coding:utf-8
def defrag_txt(txt):#for unicode
result = []
pre_is_en = False
stop_word = set(u' ,.。')
for i in txt:
num_i = ord(i)
if i not in stop_word:
if 0x4e00 <= num_i < 0x9fa6:
result.append(i)
continue
if 97 <= num_i <= 122 or 65 <= num_i <= 90:
result.append(i)
pre_is_en = True
continue
if 48 <= num_i <= 57:
result.append(i)
continue
num_diff = num_i-0xff10
if 0 <= num_diff < 10:
result.append(str(num_diff))
continue
pre_is_en = False
else:
if pre_is_en:
result.append(i)
pre_is_en = False
return ''.join(result)
print defrag_txt(u"""腾//讯○电●话:1234567890""")
腾讯电话1234567890
def defrag_txt(txt):#for unicode
result = []
pre_is_en = False
stop_word = set(u' ,.。')
for i in txt:
num_i = ord(i)
if i not in stop_word:
if 0x4e00 <= num_i < 0x9fa6:
result.append(i)
continue
if 97 <= num_i <= 122 or 65 <= num_i <= 90:
result.append(i)
pre_is_en = True
continue
if 48 <= num_i <= 57:
result.append(i)
continue
num_diff = num_i-0xff10
if 0 <= num_diff < 10:
result.append(str(num_diff))
continue
pre_is_en = False
else:
if pre_is_en:
result.append(i)
pre_is_en = False
return ''.join(result)
print defrag_txt(u"""腾//讯○电●话:1234567890""")
腾讯电话1234567890