import re WORD_REGEX = re.compile(r"([^\W_]+(?:'[^\W_]+)?)") def abbreviate(words): return ''.join(s[0].upper() for s in re.findall(WORD_REGEX, words))