# Python like dictionaries in Kotlin

**URL:** <https://discuss.kotlinlang.org/t/python-like-dictionaries-in-kotlin/2008>\
**Category:** Language Design\
**Created:** [October 4, 2016, 9:15pm UTC](https://discuss.kotlinlang.org/t/python-like-dictionaries-in-kotlin/2008 "2016-10-04T21:15:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jszczepankiewicz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jszczepankiewicz/32/2153_2.png) [@jszczepankiewicz](https://discuss.kotlinlang.org/u/jszczepankiewicz)\
**Post date:** [October 4, 2016, 9:15pm UTC](https://discuss.kotlinlang.org/t/python-like-dictionaries-in-kotlin/2008/1 "2016-10-04T21:15:08Z")

</div>

Hi,  
I’m newbe in Kotlin thus sorry if I’m asking for someting obvious. Just wondering whether it is possible to achieve something similar to Python dictionaries in Kotlin namely (pseudocode):

dict1 = {“firstName”: “John”, “age”: 31, “married”:true}

in Kotlin so:  
Some kind of map of properties of different types (Integer, Boolean, String) mapped by key (String).  
Thanks for any hints  
JS

---

<div class="post-metadata">

**Author:** ![mikehearn](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/mikehearn/32/1424_2.png) [@mikehearn](https://discuss.kotlinlang.org/u/mikehearn)\
**Post date:** [October 4, 2016, 9:25pm UTC](https://discuss.kotlinlang.org/t/python-like-dictionaries-in-kotlin/2008/2 "2016-10-04T21:25:20Z")

</div>

```
val dict1 = mapOf( 
    "firstName" to "John",
    "age" to 31,
    "married" to true
)

```

You get a `Map<String, Any>` from that sort of construct.

---

<div class="post-metadata">

**Author:** ![jan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jan/32/2152_2.png) [@jan](https://discuss.kotlinlang.org/u/jan)\
**Post date:** [October 5, 2016, 4:31pm UTC](https://discuss.kotlinlang.org/t/python-like-dictionaries-in-kotlin/2008/3 "2016-10-05T16:31:41Z")

</div>

Do you know why they decided to use ‘to’ instead of : or =\> or something else known from other languages?

---

<div class="post-metadata">

**Author:** ![medium](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/medium/32/10404_2.png) [@medium](https://discuss.kotlinlang.org/u/medium)\
**Post date:** [October 5, 2016, 7:29pm UTC](https://discuss.kotlinlang.org/t/python-like-dictionaries-in-kotlin/2008/4 "2016-10-05T19:29:43Z")

</div>

I guess, it’s because symbolic operators are (intentionally) pretty limited in Kotlin.

---

<div class="post-metadata">

**Author:** ![JanKanis](https://avatars.discourse-cdn.com/v4/letter/j/a183cd/32.png) [@JanKanis](https://discuss.kotlinlang.org/u/JanKanis)\
**Post date:** [December 26, 2016, 11:12pm UTC](https://discuss.kotlinlang.org/t/python-like-dictionaries-in-kotlin/2008/5 "2016-12-26T23:12:03Z")

</div>

`to` is syntactically not an operator but an infix extension method on `Any`. So you can define your own alternatives to `to` as long as they are valid identifiers.
