from random import choice import srtring s=string.digits+string.ascii_letters lst=[choice(s) for i in range(20)] d={x:lst.count(x) for x in set(lst)} print(d)
lst=[input("请输入:字符:") for i in range(5)] print(lst) for x in lst: print(x.upper()) # 从a-zA-Z0-9生成指定数量的随机字符: ran_str = ''.join(random.sample(string.ascii_letters + string.digits, 20)) print(ran_str) print(set(ran_str)) res_dict = {} for i in set(ran_str): res_dict.update({i: ran_str.count(i)}) print(res_dict)