Skip to content

Instantly share code, notes, and snippets.

@fish2000
Created November 6, 2012 19:55
Show Gist options
  • Select an option

  • Save fish2000/4027079 to your computer and use it in GitHub Desktop.

Select an option

Save fish2000/4027079 to your computer and use it in GitHub Desktop.
Split compound abbreviated color-scheme names into short channel titles
def split_abbreviations(s):
abbreviations = []
current_token = ''
for char in s:
if current_token is '':
current_token += char
elif char.islower():
current_token += char
else:
abbreviations.append(str(current_token))
current_token = ''
current_token += char
if current_token is not '':
abbreviations.append(str(current_token))
return abbreviations
def main():
for abbrev in ['RGB', 'CMYK', 'YCrCb', 'sRGB', 'RGBA', 'YoDoggIHeardYouLikeAbbreviations']:
print "%s: %s" % (abbrev, split_abbreviations(abbrev))
if __name__ == '__main__':
main()
"""
RGB: ['R', 'G', 'B']
CMYK: ['C', 'M', 'Y', 'K']
YCrCb: ['Y', 'Cr', 'Cb']
sRGB: ['s', 'R', 'G', 'B'] # not exactly but... judges? we'll take it
RGBA: ['R', 'G', 'B', 'A']
YoDoggIHeardYouLikeAbbreviations: ['Yo', 'Dogg', 'I', 'Heard', 'You', 'Like', 'Abbreviations']
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment