MCPcopy Index your code
hub / github.com/bugy/script-server / put_multivalue

Function put_multivalue

src/utils/collection_utils.py:9–25  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

7
8
9def 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
28def find_any(values, predicate):

Callers 2

_assert_filesMethod · 0.90
_add_valueMethod · 0.90

Calls 1

appendMethod · 0.80

Tested by 1

_assert_filesMethod · 0.72