def find_nearest_color_hexstr(hexdigits, color_table=None, method='euclid'):
    ''' Given a three or six-character hex digit string, return the nearest
        color index.

        Arguments:
            hexdigits:  a three/6 digit hex string, e.g. 'b0b', '123456'

        Returns:
            int, None: index, or None on error.
    '''
    triplet = []
    try:
        if len(hexdigits) == 3:
            for digit in hexdigits:
                digit = int(digit, 16)
                triplet.append((digit * 16) + digit)
        elif len(hexdigits) == 6:
            triplet.extend(int(hexdigits[i:i+2], 16) for i in (0, 2, 4))
        else:
            raise ValueError('wrong length: %r' % hexdigits)
    except ValueError:
        return None

    return find_nearest_color_index(*triplet,
                                    color_table=color_table,
                                    method=method)
def find_nearest_color_hexstr ( hexdigits , color_table = None , method = 'euclid' ) : triplet = [ ] try : if len ( hexdigits ) == 3 : for digit in hexdigits : digit = int ( digit , 16 ) triplet . append ( ( digit * 16 ) + digit ) elif len ( hexdigits ) == 6 : triplet . extend ( int ( hexdigits [ i : i + 2 ] , 16 ) for i in ( 0 , 2 , 4 ) ) else : raise ValueError ( 'wrong length: %r' % hexdigits ) except ValueError : return None return find_nearest_color_index ( * triplet , color_table = color_table , method = method )
Given a three or six-character hex digit string, return the nearest
        color index.

        Arguments:
            hexdigits:  a three/6 digit hex string, e.g. 'b0b', '123456'

        Returns:
            int, None: index, or None on error.