+ 1

How to get the position of strings?

mystrng="abin(Singh(rajan" now I want to know about the position of (..how to get this? can anyone help?

10th Mar 2017, 2:19 PM
Abin Singh R
Abin Singh R - avatar
6 Respostas
+ 1
I don't know if there is a right way, but according to this, "(" is located at position 5 and 11 mystrng="abin(Singh(rajan" position=0 for i in mystrng: position+=1 if i == "(": print(position-1) #count backward mystrng="abin(Singh(rajan" backward=mystrng[::-1] position=len(backward) for i in backward: position-=1 if i == "(": print(position)
10th Mar 2017, 2:27 PM
LordHill
LordHill - avatar
+ 1
index for lists start at 0. here I will change my code to represent that. there ya go, 4 and 10 now
10th Mar 2017, 2:39 PM
LordHill
LordHill - avatar
+ 1
check my code again. first one counts forward starting with 0. second one counts backward. also, per your request it counts as if the first spot is 0. so instead of 16-1 it counts 15-0
11th Mar 2017, 10:54 AM
LordHill
LordHill - avatar
0
it s 4 and 10 right.. starts with 0 know
10th Mar 2017, 2:29 PM
Abin Singh R
Abin Singh R - avatar
0
thank you so much
11th Mar 2017, 8:36 AM
Abin Singh R
Abin Singh R - avatar
0
here for i in my string: it will initialize from 1st index character. But can we do it from backward.ie from n which is the last char in this string
11th Mar 2017, 8:42 AM
Abin Singh R
Abin Singh R - avatar