def normalize_district(header, office, row):

    norm_office = normalize_races(office)
    dist_str = "".join(
        map(str, [int(s) for s in office.strip() if s.isdigit()][:2]))

    bth_regex = re.compile(r'((leg|con).*dis.*)', re.IGNORECASE)
    leg_regex = re.compile(r'leg.*dis.*', re.IGNORECASE)
    con_regex = re.compile(r'con.*dis.*', re.IGNORECASE)

    if not row:
        row = {}

    try:
        row[filter(lambda x: bth_regex.search(x), header)[0]]
        if norm_office is 'U.S. Representative':
            dist = row[filter(lambda x: leg_regex.search(x), header)[0]]
            return dist
        if norm_office in ('State Representative', 'State Senate'):
            dist = row[filter(lambda x: con_regex.search(x), header)[0]]
            return dist
    except IndexError:
        if dist_str is "":
            return None
        if int(dist_str) > 49:
            dist_str = dist_str[:1]
        return dist_str
Registers the listener for the Widget.onblur event.
dataset/ETHPy150Open openelections/openelections-core/openelex/us/wa/load.py/normalize_district--crossover with--dataset/ETHPy150Open dddomodossola/remi/remi/gui.py/Widget.set_on_blur_listener