回覆列表
-
1 # fluhr2988
-
2 # 使用者6354188383803
s="sfawaef#$#%fdf1232"
d = dict((i, s.count(i)) for i in set(s) if i.isalpha())
或
d = {i: s.count(i) for i in set(s) if i.isalpha()}
或
from string import ascii_letters
d = {i: s.count(i) for i in set(s) if i in ascii_letters}
或
from collections import Counter
from string import ascii_letters
d = Counter(i for i in s if i in ascii_letters)
或d = {i: s.count(i) for i in set(s) if i.isalpha()}或