<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def build_kw_dict(kw_list):
 """ Build keyword dictionary from raw keyword data. Ignore invalid or invalidated records. Args: kw_list (list):
 List of dicts from :func:`read_kw_file`. Returns: OrderedDict: dictionary with keyword data. """

    kw_dict = OrderedDict()
    sorted_list = sorted(
        kw_list,
        key=lambda x: x.get("zahlavi").encode("utf-8")
    )

    for keyword_data in sorted_list:
        if "zahlavi" not in keyword_data:
            continue

        zahlavi = keyword_data["zahlavi"].encode("utf-8")
        old_record = kw_dict.get(zahlavi)

        if not old_record:
            kw_dict[zahlavi] = keyword_data
            continue

        key = "angl_ekvivalent"
        if not old_record.get(key) and keyword_data.get(key):
            kw_dict[zahlavi] = keyword_data
            continue

        key = "zdroj_angl_ekvivalentu"
        if not old_record.get(key) and keyword_data.get(key):
            kw_dict[zahlavi] = keyword_data
            continue

        if len(str(keyword_data)) > len(str(old_record)):
            kw_dict[zahlavi] = keyword_data
            continue

    return kw_dict