dic=dict() d={} s=set() s='helloworld' (1)d=dict() for x in s: if x not in d.keys(): d[x]=1 else: d[x]=d[x]+1 print(d) (2)d2=dict() for x in s: d2[x]=d2.get(x,0)+1 print(d2) (3)d3=dict() for x in s: d3[x]=s.count(x) print(d3) 上面一共给出了三种方法,均是以字典的形式输出,但…
有一个字符串 “aaddfdfdercfghfyttefsfsfewretr123trefg5624sdfcgvfdgte6435234532”,现在需要取出里面出现次数最多的字符 第一种方法-装饰器 class get_max_count_string: def __init__(self,func): self.func=func self.count={} def __call__(self, args): for s in args:…