Skip to content

Instantly share code, notes, and snippets.

@svetlyak40wt
Created November 30, 2009 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save svetlyak40wt/245648 to your computer and use it in GitHub Desktop.
Save svetlyak40wt/245648 to your computer and use it in GitHub Desktop.
def parse_color(s):
""" Parses color string in format #ABC or #AABBCC to RGB tuple. """
l = len(s)
assert(l in (4,5,7,9))
if l in (4,5):
return tuple(int(ch * 2, 16) for ch in s[1:])
else:
return tuple(int(''.join(a), 16) for a in zip(*[iter(s[1:])]*2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment