import re
s1 = "This has no long words"
s2 = "This has oooone long word"
def has_long(sentence):
elong = re.compile("([a-zA-Z])\\1{2,}")
return bool(elong.search(sentence))
print has_long(s1)
False
print has_long(s2)
True
sentence = "Hoow arre you doing?"
elongated = ["hoow",'arre','youu','yoou','meee'] #You will need to have a much larger list
for word in sentence:
word = word.lower()
for e_word in elongated:
if e_word == word:
print "Found an elongated word!"
>>> from re import search
>>> mystr = "word word soooo word tooo thaaatttt word"
>>> [x for x in mystr.split() if search(r'(?i)[a-z]\1\1+', x)]
['soooo,', 'tooo', 'thaaatttt']
>>>
试试这个:
好吧,你可以把每一个被拉长的单词列成一个逻辑上可行的列表。然后循环检查句子中的单词,然后在列表中找出延长的单词。在
如果你想照休·博思韦尔说的做,那么:
^{pr2}$@HughBothwell有个好主意。据我所知,没有一个英语单词的同一个字母连续重复三次。因此,您可以搜索执行此操作的单词:
任何你找到的都会被拉长的词。在
相关问题 更多 >
编程相关推荐