[英]How to find the index of the last character of a substring in python
[英]how to find previous character and index for character
您能帮我这个忙吗,所以我想要的是,我输入文本“ hello”,我得到几秒钟一一索引的字符
对于变体2,而不是:
if lastElement == (ch - 1):
关于什么:
if lastElement == text[elmt-1]
这将产生所需的输出:
target = 'ol'
after = 'l'
before = 'e'
text = 'hello'
for elmt, ch in enumerate(text):
print(ch, elmt)
if ch in target:
print('was {}'.format(ch.upper()))
if ch == after:
if last in before:
print('before this {} was {}\n'.format(ch.upper(), last.upper()))
else:
print('before was other character not {}\n'.format(before.upper()))
last = ch
输出:
h 0
e 1
l 2
was L
before this L was E
l 3
was L
before was other character not E
o 4
was O
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.