utils
add_kv_to_dict(d, k, v, as_list=False)
Add a key-value pair to a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d |
dict[str, Any]
|
Dictionary to add the key-value pair to. |
required |
k |
str
|
Key to add. |
required |
v |
Any
|
Value to add. |
required |
as_list |
bool
|
If True, the value is appended to the list identified by |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with the key-value pair added. If the key already exists, |
dict[str, Any]
|
the value is saved as a list. |
Source code in metabolike/utils.py
chunk(itr, chunk_size)
Chunk an iterator into chunks of size chunk_size.
Ref: https://stackoverflow.com/a/71572942/5925357