flip map(a)
Group |
The function exchanges the key and the value for all key-value pairs in the map a. So the old value becomes the new key and the old key becomes the new value.
Important note: If key-value pairs with the same values exist, after calling the function the new key (created from the same old values) is occupied with the last new value (old key), since the previous ones are overwritten. The old keys (i.e. the new values) are sorted alphabetically in ascending order before being inserted into the "new" map. See examples.
Description of Parameters
Parameter |
Description |
a |
Name of the map. |
Examples
Map myMap is filled with
Key |
Value |
key1 |
value1 |
key2 |
value2 |
After calling the function, map myMap contains:
Key |
Value |
value1 |
key1 |
value2 |
key2 |
If map myMap is filled with
Key |
Value |
key1 |
value1 |
key2 |
value1 |
, map myMap will contain the following after the function call:
Key |
Value |
value1 |
key2 |