Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
classic solution in Clear category for Middle Characters by kdim
def middle(text):
l = len(text)
return text[l // 2 - 1 + l % 2:l // 2 + 1]
if __name__ == '__main__':
print("Example:")
print(middle('example'))
assert middle('example') == 'm'
assert middle('test') == 'es'
assert middle('very-very long sentence') == 'o'
assert middle('I') == 'I'
assert middle('no') == 'no'
print("Coding complete? Click 'Check' to earn cool rewards!")
Feb. 26, 2021
Comments: