import random,string
x = string.ascii_letters + string.digits + string.punctuation
y = [random.choice(x) for i in range(1000)]
z = ''.join(y)
new_dict = dict()
for i in z:
new_dict[i] = new_dict.get(i, 0) + 1
print(new_dict)
使用python生成包含1000个随机字符的字符串,然后统计每个字符的出现次数。(使用字典)
最新推荐文章于 2024-03-15 13:41:44 发布