def contrasting_color_generator():
 def rgb_to_hex(rgb):
  return (u'#%02x%02x%02x' % tuple(rgb))
 triples = [(1, 0, 0), (0, 1, 0), (0, 0, 1), (1, 1, 0), (0, 1, 1), (1, 0, 1), (1, 1, 1)]
 n = (1 << 7)
 so_far = [[0, 0, 0]]
 while True:
  if (n == 0):
   (yield u'#000000')
  copy_so_far = list(so_far)
  for triple in triples:
   for previous in copy_so_far:
    rgb = [((n * triple[i]) + previous[i]) for i in range(3)]
    so_far.append(rgb)
    (yield rgb_to_hex(rgb))
  n >>= 1

def contrasting_color_generator ( ) : def rgb_to_hex ( rgb ) : return ( u'#%02x%02x%02x' % tuple ( rgb ) ) triples = [ ( 1 , 0 , 0 ) , ( 0 , 1 , 0 ) , ( 0 , 0 , 1 ) , ( 1 , 1 , 0 ) , ( 0 , 1 , 1 ) , ( 1 , 0 , 1 ) , ( 1 , 1 , 1 ) ] n = ( 1 << 7 ) so_far = [ [ 0 , 0 , 0 ] ] while True : if ( n == 0 ) : ( yield u'#000000' ) copy_so_far = list ( so_far ) for triple in triples : for previous in copy_so_far : rgb = [ ( ( n * triple [ i ] ) + previous [ i ] ) for i in range ( 3 ) ] so_far . append ( rgb ) ( yield rgb_to_hex ( rgb ) ) n >>= 1
generate constrasting colors by varying most significant bit of rgb first .