python generate dictionary in loop

Solutions on MaxInterview for python generate dictionary in loop by the best coders in the world

showing results for - "python generate dictionary in loop"
Hepsiba
20 Oct 2020
1n = int(input())
2ans = {}
3for i in range (1,n+1):
4  ans[i] = i * i
5print(ans)
Edoardo
28 Mar 2016
1n = int(input())
2ans = {i : i*i for i in range(1,n+1)}
3print(ans)