Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
slice or middle element solution in Clear category for Middle Characters by nickgryg
def middle(text):
return text[len(text) // 2 - 1:len(text) // 2 + 1] if len(text) % 2 == 0 else text[len(text) // 2]
if __name__ == '__main__':
print("Example:")
print(middle('example'))
#These "asserts" using only for self-checking and not necessary for auto-testing
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!")
Dec. 4, 2018
Comments: