相关疑难解决方法(0)

在Python中查找所有出现的子字符串

Python已经string.find()并且string.rfind()在字符串中获取子字符串的索引.

我想知道,也许有类似的东西string.find_all()可以返回所有已创建的索引(不仅从开始或从头到尾)?

例如:

string = "test test test test"

print string.find('test') # 0
print string.rfind('test') # 15

#this is the goal
print string.find_all('test') # [0,5,10,15]
Run Code Online (Sandbox Code Playgroud)

python regex string

325
推荐指数
12
解决办法
39万
查看次数

Python - 如何在字符串中查找"重复"字符?

例如在'GATTACA'中我想找到所有'A'.

我希望持仓1,4,6.

使用'.find'方法只能给出第一个'A'的位置,而不是其余的位置.

我想知道是否有另一种方法可以让你在字符串中找到所有'重复'字符?

python

-2
推荐指数
1
解决办法
1228
查看次数

标签 统计

python ×2

regex ×1

string ×1