【问题标题】:Elongated words and combination of words in a sentence python [closed]句子python中的加长词和词组合[关闭]
【发布时间】:2013-11-04 21:55:25
【问题描述】:

我有几行,例如: 最大的傻瓜,sooo,hiiieee,足球迷

如果您注意到上面的模式,要么在 1 个单词中存在单词组合,例如“biggestfooolofall”“footballfan”。

1) 我想知道如何理解它是一个单词中的多个单词。

2) sooo 和 hiiieee 是加长词。我想在 python 中检测加长词。我该怎么做?

我是 python 新手,所以在这部分卡住了。另外,如果您可以分享任何有用的网站来学习 for 循环、字符串拆分等,那将非常有帮助

【问题讨论】:

标签: python for-loop split stringstream


【解决方案1】:

我猜你有一个有效单词的列表。因此,遍历您的单词并检查它们是否在您的行中:

for word in words:                              # iterate over all valid words
     if word in line:                           # if a valid word is found in line
         print 'I found a valid word: '+word
         line.replace(word,'')                  # remove the word from your line

最后,您会在“line”变量中找到所有有效单词和只剩下垃圾字符。

有关进一步的字符串操作,请参阅string methods

【讨论】:

  • 由于案件重叠,会比这更多涉及 - 例如'fall' in 'foolofall'。
猜你喜欢
  • 2010-10-19
  • 1970-01-01
  • 2021-02-13
  • 1970-01-01
  • 1970-01-01
  • 2012-02-02
  • 1970-01-01
  • 1970-01-01
  • 2017-11-26
相关资源
最近更新 更多