python随机生成1000个字母,数字,符号的字符串,并统计每个字符串出现的次数,利用string和random

import string
import random
x = string.digits + string.punctuation + string.ascii_letters
y = ""
for i in range(1000):
    y += random.choice(x)
num_dict = {}
for i in y:
    if i in num_dict:
        num_dict[i] += 1
    else:
        num_dict[i] = 1
for key, value in num_dict.items():
    print(key, value)
print("value总和为:"+str(sum(num_dict.values())))

 

你可能感兴趣的:(python随机生成1000个字母,数字,符号的字符串,并统计每个字符串出现的次数,利用string和random)