Skip to content

Instantly share code, notes, and snippets.

@dotangad
Created June 29, 2023 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotangad/ff7c35b927c2e8dd403c7d4400e7046e to your computer and use it in GitHub Desktop.
Save dotangad/ff7c35b927c2e8dd403c7d4400e7046e to your computer and use it in GitHub Desktop.
"""
This week’s question:
Write a function that takes an array of consecutive, increasing letters as input, and returns any missing letters in the array between the first and last letter.
Example:
> missingLetters(['a','b','c','d','f'])
> ['e']
> missingLetters(['a','b','c','d','e','h','i','j','k','l','m','n','o','p','q','r','s','t','u','w','x','y','z'])
> ['f','g','v']
"""
from typing import List
def missing_letters(letters: List[str]):
"""Given a list of letters in alphabetical order, return a list of missing letters.
>>> missing_letters(['a','b','c','d','f'])
['e']
>>> missing_letters(['a','b','c','d','e','h','i','j','k','l','m','n','o','p','q','r','s','t','u','w','x','y','z'])
['f', 'g', 'v']
"""
# The `ord` function returns the ASCII representation given a character.
# The `chr` function does the inverse (returns character given ASCII number).
return [
chr(c)
for c in range(ord(letters[0]), ord(letters[-1]))
if chr(c) not in letters
]
if __name__ == "__main__":
import doctest
doctest.testmod()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment