print the number of each character in a string

a = 'hello world'
b = []
for i in a:
    if '%s:%s' % (i, a.count(i)) not in b:
        b.append('%s:%s' % (i, a.count(i)))
print(b)

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325851989&siteId=291194637