Dictionary with loop and squared numbers

You are creating a new Dict in every loop iteration - so you basically end up with a hundred dictionaries with one entry each.

What you want is to instantiate a Dict and then simply add key-value pairs to the existing single dictionary to end up with one Dict that has a hundred entries.

Have you looked at the manual section I linked above? You might be particularly interested in the line that references creating dictionaries from comprehensions :wink:

4 Likes