例題2.11程式碼
import string
import random
x = string.ascii_letters + string.digits
y = ' '.join([random.choice(x) for i in range(1000)])
d = dict()
for ch in y:
d[ch] = d.get(ch, 0) + 1
for k, v in sorted(d.items()):
print(k, ':', v)
import string
import random
x = string.ascii_letters + string.digits
y = ' '.join([random.choice(x) for i in range(1000)])
d = dict()
for ch in y:
d[ch] = d.get(ch, 0) + 1
for k, v in sorted(d.items()):
print(k, ':', v)