如何找到ha和h的非空组合

2024-10-04 01:25:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图找到任何非空的ha和ho的组合,例如hahahoho,ha,ho,hoha

chat_words = sorted(set(w for w in nltk.corpus.nps_chat.words()))

[w for w in words.words() if re.search('^[haho]+$',w)]

我得到的结果是:

['a',
 'aa',
 'ah',
 'aha',
 'aho',
 'h',
 'ha',
 'hah',
 'hao',
 'ho',
 'o',
 'oh',
 'oho',
 'a']

Tags: inreforifchatcorpuswordssorted