ezoic

Tuesday, February 21, 2017

Solution to one python question

Write a function 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

looking for a man

 I am a mid aged woman.  I was born in 1980. I do not have any kid. no complicated  dating before . I am looking for a man here for marriage...