Editor

The Middle Letter

#523 · Strings · Beginner · 25 XP · about 4 min

Write middle(word) that returns the middle of word.

  • A word with an odd number of letters has one middle letter: 'apple' gives 'p'.
  • A word with an even number of letters has two middle letters, and both are returned: 'moon' gives 'oo'.
  • An empty string gives an empty string.

Examples

middle('apple')   # returns 'p'
middle('moon')    # returns 'oo'
middle('python')  # returns 'th'
middle('a')       # returns 'a'

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.