给出一个字符串,在程序中赋初值为一个句子,例如comment=“To improve is to change;to be perfect is to change often.” 需要:计算句子中各字符出现的次数
set1=set(comment)
for i in set1:
print(i,'共出现',comment.count(i),'次')
dict={}
for i in comment:
dict[i]=comment.count(i)
for key in dict:
print(key,dict[key])
i=0
dicta ={}
while i < len(comment):
dicta.update({comment[i]:comment.count(comment[i])})
i+=1
for k,v in dicta.items():
print(f'{k}一共出现了{v}次')
count={}
for i in comment:
count.setdefault(i,0)
count[i]=count[i]+1
print(count)
生成100个卡号,具体要求如下: —-1. 卡号以6102009开头, 后面3位依次是 (001, 002, 003…… 100) —-2. 生成关于银行卡号的字典, 默认每个卡号的初始密码为”redhat”;