here HEX2RGB return dict value after conversion like {r:255,g:255,b:255}
rgbValue=HEX2RGB(hex,'dict')
r,g,b={rgbValue} # not working
so how can I assign value of each key r,g,b in the variables r,g,b like above method? or is there any other efficient way?
Use operator.itemgetter, which will not rely on any particular ordering returned by HEX2RGB;
from operator import itemgetter
dictToTuple = itemgetter('r', 'g', 'b')
r, g, b = dictToTuple(HEX2RGB(hex,'dict'))
if your type is a dictionary (assumption cause you wrote {r:255,g:255,b:255})
r,g,b = rgbValue.get('r'),rgbValue.get('g'),rgbValue.get('b')
More Pythonic way:
dict = {'r':255,'g':255,'b':255}
r,g,b = dict.values()
print(r)
print(g)
print(b)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With