Created
November 6, 2012 19:55
-
-
Save fish2000/4027079 to your computer and use it in GitHub Desktop.
Split compound abbreviated color-scheme names into short channel titles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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