字典列表 转为 具名元组列表
def tuplify_dicts(dicts: list): # 字典列表 转为 具名元组列表 keys = {key for line in dicts for key in line.keys()} Struct = namedtuple('Struct', sorted(keys), rename=True) # rename=True 防止重名或者无效名字 Struct.__new__.__defaults__ = (None, ) * len(Struct._fields) return [Struct(**dict_l) for dict_l in dicts]