![Kotlin map not null](https://cdn3.cdnme.se/5447227/9-3/screenshot_3_64e629479606ee7f889a24a8.jpg)
The reason for this is the contract of the Map interface, which says: Instead, it provides a default value for unknown keys, which can be really helpful for grouping and counting algorithms like the following one: from collections import defaultdictĭata = The defaultdict can also be used with other types and makes sure that you don't get a KeyError when running your code. You can find the Python defaultdict documentation and some examples here but the basic use case is shown in the following snippet: from collections import defaultdict Kotlin also comes with a similar tool which I want to demonstrate in this little article. Have you ever used a default map or default dict before? If you know Python a bit, you probably saw its defaultdict in action at some point. By s1m0nw1 1 Comment Does Kotlin have a default Map?
![Kotlin map not null](https://cdn3.cdnme.se/5447227/9-3/screenshot_3_64e629479606ee7f889a24a8.jpg)