def proper_range(fir, sec):
    '''
    >>> valid = [(3, 10), (71, 72), (96, 117), (100, 104), (1100, 1113), (101, 8), (1103, 4), (321, 28), (212, 302), (1496, 1504), (498, 532)]
    >>> all([proper_range(*pair) for pair in valid])
    True

    >>> invalid = [(71, 2), (1103, 2), (321, 20), (321, 328)]
    >>> any([proper_range(*pair) for pair in invalid])
    False

    '''
    
    if fir < 100:
        if sec < fir:
            #print "** fir < 100 and didn't use all digits" 
            return False # (12, 3)
        else:
            return True # (12, 13)

    if fir % 100 == 0:
        if fir > sec:
            #print "** fir multiple of 100 and didn't use all digits" 
            return False # (100, 4)
        else:
            return True # (100, 104)

    if len(str(fir)) == len(str(sec)) and int(str(fir)[0]) == int(str(sec)[0]):
        if len(str(fir)) > 3:
            if all(a != b for a,b in zip(str(fir), str(sec))[1:]): 
                return True # (1496, 1504)
            else:
                #print "** not all least significant digits changed in 4+ digit number"
                return False # (1496, 1506)
        else:
            if fir < sec:
                #print "** used more digits than needed" # (389, 391)
                return False
            else:
                return True # (498, 532)

    if int(str(fir)[-len(str(sec)):]) > sec:
        #print "** first is larger than second" 
        return False #(1103, 102)

    #print "** defaulting to true"
    return True

    >>> valid = [(3, 10), (71, 72), (96, 117), (100, 104), (1100, 1113), (101, 8), (1103, 4), (321, 28), (212, 302), (1496, 1504), (498, 532)]
    >>> all([proper_range(*pair) for pair in valid])
    True

    >>> invalid = [(71, 2), (1103, 2), (321, 20), (321, 328)]
    >>> any([proper_range(*pair) for pair in invalid])
    False

    
recipes/Python/576889_CMS_page_range_validator/recipe-576889.py