17 lines
394 B
Python
17 lines
394 B
Python
|
|
import re
|
||
|
|
|
||
|
|
|
||
|
|
def convert_camel_case_to_snake_case(name):
|
||
|
|
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
|
||
|
|
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
|
||
|
|
|
||
|
|
|
||
|
|
def convert_dict_keys_to_snake_case(a_dict):
|
||
|
|
new_dict = {}
|
||
|
|
for old_key in a_dict.keys():
|
||
|
|
new_key = convert_camel_case_to_snake_case(old_key)
|
||
|
|
new_dict[new_key] = a_dict[old_key]
|
||
|
|
return new_dict
|
||
|
|
|
||
|
|
|