How do you remove or delete a single 'key:value' item from a dictionary?

I see an ‘add’ and ‘extend’ operator for a dictionary, so how do you remove a single ‘key:value’ entry from a dictionary?

Thanks
Tom

Set the key’s value to nothing, i.e."", or 0, etc., if a data type is assume for the value depending of data type. For a list value use -= to remove the item from the value list.

Edit: see more accurate answer further below.

1 Like

Actually, I think the expected method is Dictionary.add(), q.v..

Set a value - as a list (note the use of a [ ] list syntax);

$MyDictionary =$MyDictionary.add({fruit:[apple;pear]});

Set it to a single value:

$MyDictionary =$MyDictionary.add({fruit:orange});

Set key “fruit” to now value, i.e. delete ‘orange’

$MyDictionary=$MyDictionary.add({fruit:});

This retains the key ‘fruit’ but it has no value set.

To remove a key and implicitly, all its value(s) a different approach is needed. To delete the key ‘fruit’:

$MyDictionary-="fruit";
1 Like

I’ve updated Dictionary.add(itemDict) to link to the Dictionary-Type Attributes page, which describes deleting keys.

I believe this closes some missing cross-references in aTbRef. From a user stand-point, wanting to delete a value seems an entirely reasonable request , even if from an app standpoint there may be ambiguity whether this means deleting just the value or the key+value(s)—and differences of single item vs multi-item values..

I hope this is now covered, but if insufficiently clear do please comment. If doing so please cite the aTbRef article being read and where the description became unclear (it’s much harder to fix “it doesn’t make sense”!).

1 Like