0
The code isn't working
So, I have a code that must return text between two characters: cont = ("0. ZEROZEROZERO: Isome textt> 1.ONENEONE: some other text, 2. TWOTWOTWOwtqwhw: 3.THREE: qweqweqeqwe 4.FOURFOUR: qrqrqrqrqr, 5.FIVEFIVE:") def find_between(text, first, last): try: start = text.index(str(first)) end = text.index(last) print(text[start:end]) except ValueError: return "" find_between(cont, 3, ":") The code must print text between 3 and ":" But it's not printing anything, but the code runs correctly if I search between zero and ":"
3 Answers
+ 3
your first case works as start and end index is fine.....
for rest all cases , always search result for : is lesser than your start value...
just do below change in code and it should be fine :
end = text.find(last,start)
above should always find last character after first character index
+ 3
start = text.index(first + '.')
Don't know if this is the only issue
+ 1
Thank you so much!