Skip to content

Instantly share code, notes, and snippets.

@rougeth
Created February 8, 2017 12:47
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 rougeth/301d862155da380ca930aa3713052085 to your computer and use it in GitHub Desktop.
Save rougeth/301d862155da380ca930aa3713052085 to your computer and use it in GitHub Desktop.
from functools import reduce
def center(words):
max_length = reduce(lambda a, b: a if a > len(b) else len(b), words, 0)
words = [word if len(word) == max_length else '{}{}'.format(' ' * ((max_length - len(word)) // 2), word) for word in words]
for word in words: print(word)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment