def rgb_to_hex(rgb):
r, g, b = rgb[:<NUM_LIT:3>]<EOL>if (r < <NUM_LIT:0>) or (g < <NUM_LIT:0>) or (b < <NUM_LIT:0>):<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>if (r > <NUM_LIT:255>) or (g > <NUM_LIT:255>) or (b > <NUM_LIT:255>):<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>if (<NUM_LIT:0> < r < <NUM_LIT:1>) or (<NUM_LIT:0> < g < <NUM_LIT:1>) or (<NUM_LIT:0> < b < <NUM_LIT:1>):<EOL><INDENT>if (r > <NUM_LIT:1>) or (g > <NUM_LIT:1>) or (b > <NUM_LIT:1>):<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT><DEDENT>if (<NUM_LIT:0> <= r <= <NUM_LIT:1>) and (<NUM_LIT:0> <= g <= <NUM_LIT:1>) and (<NUM_LIT:0> <= b <= <NUM_LIT:1>):<EOL><INDENT>rgb = tuple([int(round(val * <NUM_LIT:255>)) for val in [r, g, b]])<EOL><DEDENT>else:<EOL><INDENT>rgb = (int(r), int(g), int(b))<EOL><DEDENT>result = '<STR_LIT>' % rgb<EOL>return result.lower()<EOL>
Utility function to convert (r,g,b) triples to hex.
http://ageo.co/1CFxXpO
Args:
  rgb (tuple): A sequence of RGB values in the
    range 0-255 or 0-1.
Returns:
  str: The hex code for the colour.