Innovenergy_trunk/python/gui/flatten.py

33 lines
1000 B
Python
Raw Normal View History

2023-02-16 12:57:06 +00:00
def flattenDevice(device: dict) -> dict:
flattenedDict = {}
for key in device.keys():
typ = type(device[key])
if typ is str or typ is int or typ is float:
flattenedDict.update({str(device["Type"]) + "/" + str(key): device[key]})
elif typ is dict:
flat = flattenDict(device[key])
flattenedDict.update({str(device["Type"]) + "/" + str(key): {}})
for key2 in flat.keys():
flattenedDict[str(device["Type"]) + "/" + str(key)].update({key2: flat[key2]})
elif typ is list:
flattenedDict.update({str(device["Type"]) + "/" + str(key): device[key]})
return flattenedDict
def flattenDict(device: dict) -> dict:
flattenedDict = {}
typ = type(device)
if typ is str or typ is int or typ is float:
flattenedDict.update({"": device})
elif typ is dict:
return device
elif typ is list:
flattenedDict.update({"": device})
return flattenedDict