Today saw a very interesting question:
Analysis: The problem there is fast and statistics
1. Generator
2. Statistical dictionary
The following code is able to initiate:
import string
import random
class ITer_:
def __init__(self):
self.chars = string.ascii_letters + string.digits
def __iter__(self):
for _ in range(200):
codes =[]
for _ in range(4):
codes.append("".join(random.choices(self.chars, k=5)))
# random.shuffle(codes)
yield "-".join(codes)
result = "".join([x.stri("-") for x in ITer_()])
# 注意 strip 和repalce
count_tmp = {}
for k in result:
count_tmp[k] = count_tmp.get(k, 0) + 1
Borrowing a string and random extensions, we are interested can look at their source code, very interesting.