def get_solo(text):
duels=[x+x for x in list('。,!')]
#如需增加标点符号,比如问号,直接将list('。,!')换成list('。,!?')即可.
for d in duels:
while d in text:
text=text.replace(d,d[0])
return text
if __name__=='__main__':
text='开开心心,,,,上上。。。好好的!!'
print(get_solo(text))
结果:
>>>
开开心心,上上。好好的!
#!/usr/bin/env python
# coding: utf-8
#
# filename: baidu.py
# date: Dec., 2013
sybmchr = set([u',', u'。', u'!'])
context = u'开开心心,,,,上上。。。好好的!!'
ostr, remmind = u'', u''
for c in context:
if c in sybmchr:
if remmind==c:
continue
else:
remmind = c
ostr += c
print ostr.encode("utf-8")
先转成unicode,然后判断每个字符是不是标点,如果是,判断后面一个字符是不是,两个条件都满足就把后面的删掉吧