| Conditions | 3 |
| Total Lines | 15 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | # -*- coding: utf-8 -*- |
||
| 12 | def flatten(d, separator='_', **kwargs): |
||
| 13 | new_dict = d.copy() |
||
| 14 | new_dict.clear() |
||
| 15 | keys = list(d.keys()) |
||
| 16 | base_key = kwargs.pop('base_key', '') |
||
| 17 | for key in keys: |
||
| 18 | value = d.get(key, None) |
||
| 19 | new_key = _flatten_key(base_key, key, separator) |
||
| 20 | if type_util.is_dict(value): |
||
| 21 | new_value = flatten(value, separator=separator, base_key=new_key) |
||
| 22 | new_value.update(new_dict) |
||
| 23 | new_dict.update(new_value) |
||
| 24 | continue |
||
| 25 | new_dict[new_key] = value |
||
| 26 | return new_dict |
||
| 27 |