code: def rgb2hex(rgb, force_long=False):
      
  
      hx = ''.join(["%02x" % int(c * 255 + 0.5 - FLOAT_ERROR)
                    for c in rgb])
  
      if not force_long and hx[0::2] == hx[1::2]:
          hx = ''.join(hx[0::2])
  
      return "#%s" % hx
docs: Transform RGB tuple to hex RGB representation
  
      :param rgb: RGB 3-uple of float between 0 and 1
      :rtype: 3 hex char or 6 hex char string representation
  
      Usage
      -----
  
      >>> from colour import rgb2hex
  
      >>> rgb2hex((0.0,1.0,0.0))
      '#0f0'
  
      Rounding try to be as natural as possible:
  
      >>> rgb2hex((0.0,0.999999,1.0))
      '#0ff'
  
      And if not possible, the 6 hex char representation is used:
  
      >>> rgb2hex((0.23,1.0,1.0))
      '#3bffff'
  
      >>> rgb2hex((0.0,0.999999,1.0), force_long=True)
      '#00ffff'