def get_dict_leaves_count(dic): """ If value of a key is a list, count all items in the list as leaves. :param dic: :return: """ if len(dic) == 0: return 0 else: cnt = 0 for k, v in dic.items(): if not isinstance(v, dict): if not isinstance(v, list): cnt += 1 else: cnt += len(v) else: cnt += get_dict_leaves_count(v) return cnt