import yaml with open('dict.yaml', 'r', encoding='utf-8') as f: dict_rec = yaml.safe_load(f) print(len(dict_rec['character_dict']))