Puts a value in a dict. If key already exists, then value will be appended to existing value(s) as a list. Behavior is described by the following cases: - key not exists: just put value in dict - key has a single value: new list is created for [old_value,new_value] and stored in
(some_dict, key, value)
| 7 | |
| 8 | |
| 9 | def put_multivalue(some_dict, key, value): |
| 10 | """ |
| 11 | Puts a value in a dict. If key already exists, then value will be appended to existing value(s) as a list. |
| 12 | Behavior is described by the following cases: |
| 13 | - key not exists: just put value in dict |
| 14 | - key has a single value: new list is created for [old_value,new_value] and stored into dict |
| 15 | - key has multiple values: new_value is appended to the list |
| 16 | :param dict: where to put new element |
| 17 | :param key: co |
| 18 | :param value: new value to add |
| 19 | """ |
| 20 | if key not in some_dict: |
| 21 | some_dict[key] = value |
| 22 | elif isinstance(some_dict[key], list): |
| 23 | some_dict[key].append(value) |
| 24 | else: |
| 25 | some_dict[key] = [some_dict[key], value] |
| 26 | |
| 27 | |
| 28 | def find_any(values, predicate): |