So I've been trying to solve this for a while now. I've almost had it but never saved the code lol.... anyways, I'm trying to find if the input string has a certain (the 'e') letter in the middle, like:
how to I find the index number of a string?? and how do I find if that index is that letter?
thanks in advance!
You can check if a middle letter exists by determining whether the number of letters in the string is odd. Once that's been resolved, you can just halve the length of the string to get the index of the middle letter:
len(s) % 2 == 1 and s[len(s)//2] == "e"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.