Similar to Python's built in `dictionary[key] = value`, but takes a list of nested keys instead of a single key. set_value({'a': 1}, [], {'b': 2}) -> {'a': 1, 'b': 2} set_value({'a': 1}, ['x'], 2) -> {'a': 1, 'x': 2} set_value({'a': 1}, ['x', 'y'], 2) -> {'a
(self, dictionary, keys, value)
| 355 | } |
| 356 | |
| 357 | def set_value(self, dictionary, keys, value): |
| 358 | """ |
| 359 | Similar to Python's built in `dictionary[key] = value`, |
| 360 | but takes a list of nested keys instead of a single key. |
| 361 | |
| 362 | set_value({'a': 1}, [], {'b': 2}) -> {'a': 1, 'b': 2} |
| 363 | set_value({'a': 1}, ['x'], 2) -> {'a': 1, 'x': 2} |
| 364 | set_value({'a': 1}, ['x', 'y'], 2) -> {'a': 1, 'x': {'y': 2}} |
| 365 | """ |
| 366 | if not keys: |
| 367 | dictionary.update(value) |
| 368 | return |
| 369 | |
| 370 | for key in keys[:-1]: |
| 371 | if key not in dictionary: |
| 372 | dictionary[key] = {} |
| 373 | dictionary = dictionary[key] |
| 374 | |
| 375 | dictionary[keys[-1]] = value |
| 376 | |
| 377 | @cached_property |
| 378 | def fields(self): |