Created
October 6, 2017 18:03
-
-
Save hughdbrown/470e291aa5c1e306fe48247524b52bfb to your computer and use it in GitHub Desktop.
Find name of maximum rgb element in a string
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
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