python - 查找某个字符在单词中第一次出现的位置

标签 python

我正在尝试做的事情: 通过过滤下列表,创建并打印满足以下所有条件的单词列表:

单词长度至少为 6 个字符; 该单词包含字母“e”至少 3 次; 字母“e”第一次出现在单词的后半部分。

到目前为止我有这个: 之前使用过:

words = [ line.strip() for line in file(DATA+'english_wordlist.txt') ]

(lowers 在我之前的工作中被定义为部分单词集)

[word for word in lowers if len(word)>=6 and word.count('e')>=3 and 'e' is after word(len(word)/2::)]

我知道“e”在 word(len(word)/2::) 之后是错误的,但这只是我的粗略逻辑。我到底该如何实现这一目标?

最佳答案

and word.index('e') >= len(word)/2

关于python - 查找某个字符在单词中第一次出现的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12588893/

相关文章:

python - Discord.py 静音命令

python - 从 glTranslatef 切换到 gluLookAt 后,opengl 将不会呈现所需的输出

python - 对 Groovy 脚本调用的 Python 脚本中的异常进行编码

python - 编写面向对象的摩尔斯电码翻译器

python - 将键添加到具有自动递增值的字典

python - 当记录不按顺序时,df1 减去 df2 在 Pyspark 中无法按预期工作

python - MySQL插入语句在Python中不起作用

Python pandas 对 groupby 结果进行排序

python - 打印给定月份和年份的天数 [Python]

Python:交叉索引numpy数组