char_freq()
that takes a string and builds a frequency listing of the characters contained in it. Represent the frequency listing as a Python dictionary. Try it with something like char_freq("abbabcbdbabdbdbabababcbcbab")
.class Solution:
def char_freq1(self, string1):
dict={}
a1=list(string1)
for item in a1:
dict[item]=0
for item in a1:
if item in dict.keys():
dict[item]=dict[item]+1
return dict
kk=Solution()
if __name__=="__main__":
print(kk.char_freq1("aaaaadddeerraattqqqiiifehtysjy"))
result:
No comments:
Post a Comment