Merge pull request #15200 from wimnat/feature/handle_lists_in_snake_dict_creation

Handle lists during dict recursion
pull/15144/head
Brian Coca 9 years ago
commit e1461ef792

@ -276,10 +276,27 @@ def camel_dict_to_snake_dict(camel_dict):
return all_cap_re.sub(r'\1_\2', s1).lower()
def value_is_list(camel_list):
checked_list = []
for item in camel_list:
if isinstance(item, dict):
checked_list.append(camel_dict_to_snake_dict(item))
elif isinstance(item, list):
checked_list.append(value_is_list(item))
else:
checked_list.append(item)
return checked_list
snake_dict = {}
for k, v in camel_dict.iteritems():
if isinstance(v, dict):
v = camel_dict_to_snake_dict(v)
snake_dict[camel_to_snake(k)] = camel_dict_to_snake_dict(v)
elif isinstance(v, list):
snake_dict[camel_to_snake(k)] = value_is_list(v)
else:
snake_dict[camel_to_snake(k)] = v
return snake_dict

Loading…
Cancel
Save