尝试计算lst=('abcdefgabc')
lst=('abcdefgabc')
for i in lst:
lst.count(i)
print(i,(lst.count(i)))
输出应为a=2, b=2, c=2, d=1,e=1,f=1,g=1
答案 0 :(得分:0)
这是您要找的东西吗?
lst=('abcdefgabc')
new_list = []
for i in lst:
a = i+"="+str((lst.count(i)))
new_list.append(a)
b = sorted(set(new_list))
print(b)
for x in b:
print(x)
输出:
['a=2', 'b=2', 'd=1', 'c=2', 'f=1', 'e=1', 'g=1']
a=2
b=2
d=1
c=2
f=1
e=1
g=1