Skip to content

Instantly share code, notes, and snippets.

@hughdbrown
Created October 6, 2017 18:03
Show Gist options
  • Save hughdbrown/470e291aa5c1e306fe48247524b52bfb to your computer and use it in GitHub Desktop.
Save hughdbrown/470e291aa5c1e306fe48247524b52bfb to your computer and use it in GitHub Desktop.
Find name of maximum rgb element in a string
r = r'^rgba\((?P<red>\d+), (?P<green>\d+), (?P<blue>\d+), \d\.\d+\)$'
def max_rgba(color):
keys = ('red', 'green', 'blue')
d = {
k: int(v)
for k, v in zip(
keys,
re.search(r, color).group(*keys)
)
}
return max(d.items(), key=lambda x: x[1])[0]
print(max_rgba('rgba(127, 191, 65, 1.0)'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment