2010-02-23から1日間の記事一覧
Using empty list and it creates an index. If character exists, dictionary will be updated by number. st = 'aaavbbaa' lis = [] di = {} for i in st: if i not in lis: lis.append(i) di[i]=1 else: di[i]+=1 >>>di {'a': 5, 'b': 2, 'v': 1}