# add-value-to-dictionary

## Description

<mark style="color:purple;">`add-value-to-dictionary`</mark> *adaptor is used to add a key-value pair to an existing dictionary, or to a new dictionary if the* `dictionary` *input is not specified*.

By default, the adaptor will update the value if the key is already existing in the input dictionary. This can be changed by setting `overwrite` input to `False`.

## Inputs

**`dictionary`**\
Type: `dictionary`\
Required: No\
The dictionary to which the value will be added. If unspecified, the value will be added to a new dictionary.

**`key`**\
Type: `text`\
Required: Yes\
The key to be added to the dictionary.

**`value`**\
Type: `text`\
Required: Yes\
The value to be added to the dictionary.

**`overwrite`**\
Type: `boolean`\
Required: No\
Whether to overwrite the value if the specified key already exists in the dictionary. If unspecified, defaults to `True`.

## Outputs

**`dictionary`**\
Type: `dictionary`\
A dictionary containing the added value.

## Examples

### Example 1: Default behaviour.

#### Inputs:

`dictionary`:

<table><thead><tr><th width="100">KEY</th><th width="200">VALUE</th></tr></thead><tbody><tr><td>GB</td><td>United Kingdom</td></tr><tr><td>TR</td><td>Turkey</td></tr></tbody></table>

`key`: US `value`: United States

#### Outputs:

`dictionary`:

<table><thead><tr><th width="98">KEY</th><th width="200">VALUE</th></tr></thead><tbody><tr><td>GB</td><td>United Kingdom</td></tr><tr><td>TR</td><td>Turkey</td></tr><tr><td>US</td><td>United States</td></tr></tbody></table>

-> Added a new key-value pair { `US`: "`United States`" } to an existing dictionary.

### Example 2: Adding a key-value pair to a new dictionary.

#### Inputs:

`key`: GB

`value`: United Kingdom

#### Outputs:

`dictionary`:

<table><thead><tr><th width="100">KEY</th><th width="200">VALUE</th></tr></thead><tbody><tr><td>GB</td><td>United Kingdom</td></tr></tbody></table>

-> Added a key-value pair { `GB`: "`United Kingdom`" } to a new dictionary.

### Example 3: Updating an existing key in a dictionary.

#### Inputs:

`dictionary`:

<table><thead><tr><th width="100">KEY</th><th width="200">VALUE</th></tr></thead><tbody><tr><td>GB</td><td>United Kingdom</td></tr><tr><td>TR</td><td>Turkey</td></tr></tbody></table>

`key`: TR

`value`: Turkiye

#### Outputs:

`dictionary`:

<table><thead><tr><th width="100">KEY</th><th width="200">VALUE</th></tr></thead><tbody><tr><td>GB</td><td>United Kingdom</td></tr><tr><td>TR</td><td>Turkiye</td></tr></tbody></table>

-> Updated an existing dictionary with the key-value pair { `TR`: "`Turkiye`" }.

### Use Cases

* Represent associative data where there is a clear relationship between keys and values, such as mapping country codes to country names.
* Facilitate language translation by using key-value pairs where keys represent phrases or terms in one language, and values represent their translations in another language.
