snake_to_PascalCase

snake_to_PascalCase
SHARE

A twist on the previous Recursively Modify Python Dictionary, this function will modify a Python dictionary to convert snake_case keys to PascalCase keys.

def snake_to_PascalCase(d): for k, v in d.copy().items(): if isinstance(v, dict): d.pop(k) d[k.title().replace("_", "")] = v snake_to_PascalCase(v) elif isinstance(v, list): d.pop(k) d[k.title().replace("_", "")] = v for i in v: v.remove(i) v.append(snake_to_PascalCase(i)) else: d.pop(k) d[k.title().replace("_", "")] = v return d