curriculum/challenges/english/blocks/daily-coding-challenges-python/69b58ce40693f140c84c8559.md
Given a string, determine if it's a palindrome and return the middle character (if it's odd length) or middle two characters (if it's even).
"none".palindrome_locator("racecar") should return "e".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(palindrome_locator("racecar"), "e")`)
}})
palindrome_locator("level") should return "v".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(palindrome_locator("level"), "v")`)
}})
palindrome_locator("freecodecamp") should return "none".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(palindrome_locator("freecodecamp"), "none")`)
}})
palindrome_locator("noon") should return "oo".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(palindrome_locator("noon"), "oo")`)
}})
palindrome_locator("11100111") should return "00".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(palindrome_locator("11100111"), "00")`)
}})
def palindrome_locator(s):
return s
def palindrome_locator(s):
if s != s[::-1]:
return "none"
mid = len(s) // 2
return s[mid] if len(s) % 2 == 1 else s[mid - 1] + s[mid]