0
Python 2.7:我想知道是否有列表的索引操作的反转版本。我无法使用index
,因为不匹配的值未知。Python:第一个不匹配的字符的索引?
下面是一个例子:
myString = "aaaaaxcbaa"
pos = myString.not_index('a')
# pos should be 5
myString = "bbzcbaa"
pos = myString.not_index('b')
# pos should be 2
myString = "xxxxx"
pos = myString.not_index('x')
# this can throw an error similar to "index"
难道这样的事情存在?
现在我只是逐项迭代列表,但感觉这应该是更简单一些。
作品,非常优雅。 – fdmillion