python从字典生成词云
Given a number N, and we have to generate a dictionary that contains numbers and their squares (i, i*i) using Python.
给定一个数字N,我们必须使用Python生成一个包含数字及其平方(i,i * i)的字典。
Example:
例:
Input:
n = 10
Output:
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100}
Program:
程序:
# Python program to generate and print
# dictionary of numbers and square (i, i*i)
# declare and assign n
n = 10
# declare dictionary
numbers = {}
# run loop from 1 to n
for i in range(1, n+1):
numbers[i] = i * i
# print dictionary
print numbers
Output
输出量
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100}
翻译自: https://www.includehelp.com/python/generate-dictionary-of-numbers-and-their-squares-from-1-to-N.aspx
python从字典生成词云