I want to program this function from C to Python but the condition on the return is hard to convert:
In C:
int pos(int b) {
char *r = strchr(a, b);
return r?(r - a):-1;
}
Here what I tried:
def pos(b) :
r = alphabet[a.rfind(b):]
return r if (r - len(a)) else -1
The r variable is the same but the problem is the ternary operator. So of course, it doesn't do the same work :/ Can you help me?