fork download
  1. def hex_to_rgb(value):
  2. value = value.lstrip('#')
  3. lv = len(value)
  4. return tuple(int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3))
  5.  
  6. def rgb_to_hex(rgb):
  7. return '#%02x%02x%02x' % rgb
  8. # Resultados
  9. print hex_to_rgb("#123456") # (18, 52, 86)
  10. print hex_to_rgb("#ffffff") # (255, 255, 255)
  11. print hex_to_rgb("#ffffffffffff") # (65535, 65535, 65535)
  12. print rgb_to_hex((18, 52, 86)) # #123456
  13. print rgb_to_hex((255, 255, 255)) # #ffffff
  14. print rgb_to_hex((65535, 65535, 65535)) # #ffffffffffff
  15.  
Success #stdin #stdout 0.01s 9016KB
stdin
Standard input is empty
stdout
(18, 52, 86)
(255, 255, 255)
(65535, 65535, 65535)
#123456
#ffffff
#ffffffffffff