def convert_to_two_letter_code(lc): if len(lc) == 2: return lc lang = langs_by_code.get(lc) if lang: return lang['two'] return lc