# Can't create dictionary with integer keys in python script

**URL:** <https://forum.dynamobim.com/t/cant-create-dictionary-with-integer-keys-in-python-script/58092>\
**Category:** Revit\
**Created:** [December 8, 2020, 9:23am UTC](https://forum.dynamobim.com/t/cant-create-dictionary-with-integer-keys-in-python-script/58092 "2020-12-08T09:23:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vancikv](https://avatars.discourse-cdn.com/v4/letter/v/65b543/32.png) [@vancikv](https://forum.dynamobim.com/u/vancikv)\
**Post date:** [December 8, 2020, 9:23am UTC](https://forum.dynamobim.com/t/cant-create-dictionary-with-integer-keys-in-python-script/58092/1 "2020-12-08T09:23:09Z")

</div>

I’m working with Revit 2021. Within a python script, I wanted to create a dictionary with integer values as keys but got an error

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/c/dc83c25c2ff25abe6a2f46c29a616b80c1559c18.png)

This is very strange because python itself allows this. Also, I did it before in Dynamo, although not Revit 2021 - has anything changed or am I missing something?

---

<div class="post-metadata">

**Author:** ![3Pinter](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/3pinter/32/74327_2.png) [@3Pinter](https://forum.dynamobim.com/u/3Pinter)\
**Post date:** [December 8, 2020, 10:29am UTC](https://forum.dynamobim.com/t/cant-create-dictionary-with-integer-keys-in-python-script/58092/2 "2020-12-08T10:29:10Z")

</div>

what are you trying to do? It seems you want the index of IN[0]?  
what is you IN[0]?

if you are using a integer list in IN[0] … that won’t work since lns[i] will be out of range …

btw: “range(len(lns))” is the same as using just “lns”

```
mylist2 = [2, 4, 56, 477]
mydict = {}
for index, val in enumerate(mylist2):
    mydict[index] = val

print mydict
# {0: 2, 1: 4, 2: 56, 3: 477}
```

---

<div class="post-metadata">

**Author:** ![vancikv](https://avatars.discourse-cdn.com/v4/letter/v/65b543/32.png) [@vancikv](https://forum.dynamobim.com/u/vancikv)\
**Post date:** [December 8, 2020, 11:37am UTC](https://forum.dynamobim.com/t/cant-create-dictionary-with-integer-keys-in-python-script/58092/3 "2020-12-08T11:37:20Z")

</div>

Thanks for the answer. I didn’t realize the ambiguity, IN[0] is itself a list of line objects.

There is no error in my syntax actually. I have just found out that the error only occurs when I try to pass the dictionary out of the python script and into Dynamo. As long as the dictionary is only used within the script, it works fine. When I pass it out, it looks like it automatically tries to convert integer keys to strings and fails.

So is it Dynamo itself that cannot handle integer keys? Can anyone clarify?

---

<div class="post-metadata">

**Author:** ![Francois\_Labonne](https://avatars.discourse-cdn.com/v4/letter/f/bcef8e/32.png) [@Francois\_Labonne](https://forum.dynamobim.com/u/Francois_Labonne)\
**Post date:** [December 8, 2020, 11:51am UTC](https://forum.dynamobim.com/t/cant-create-dictionary-with-integer-keys-in-python-script/58092/4 "2020-12-08T11:51:28Z")

</div>

Hi @vancikv  
Yes, in Dynamo, dictionary keys are only strings

---

<div class="post-metadata">

**Author:** ![vancikv](https://avatars.discourse-cdn.com/v4/letter/v/65b543/32.png) [@vancikv](https://forum.dynamobim.com/u/vancikv)\
**Post date:** [December 8, 2020, 12:05pm UTC](https://forum.dynamobim.com/t/cant-create-dictionary-with-integer-keys-in-python-script/58092/5 "2020-12-08T12:05:34Z")

</div>

Thanks. Good thing I only need the dictionary inside the script. I only passed it out to check the value.
