like
var x: int var dic: Dictionary = {} for i in range(3): x = i dic.x = x
will result in dic = {0: 0, 1: 1, 2:2}
Actually found the answer reading again the docs. This is possible with the use of square brackets notation. The assignment in the question's example should look like this: dic[x] = x then you'll get the desired result. I'm surprised that I was unable to find any explicit mention of this use case in the docs...