Most, but not all, languages come with some kind of map interface built-in. Notably, the C language does not (but C++ does).
You can implement a map in many ways. Here are some examples:
__hash__method in Python, or the
hashCodemethod in Java).
Note that although a general-purpose map is useful for many problems, it is not always ideal for a particular problem. For example, although you can use a map as a set, it’s a bit of a waste of space — it’s a set of key-value pairs, but you only need the key. Similarly, maybe you need not only to take the unique elements from a group of elements, but also to print them out in sorted order. If your dictionary type is implemented as a hash table, you’ll have to sort the keys (at an additional cost of O(n lg n) plus the memory allocation to store the keys in an array). By contrast, if your dictionary is implemented as a binary search tree, after you are done inserting all the elements, they’ll already be sorted. (The trade-off is that it might have cost more to insert the elements. When in doubt, test!)
It’s a good exercise to implement a map yourself, in at least one way, in at least one language. I recommend starting with a simple hash table, and then working up to a good binary search tree like a red-black tree.