2019-10-09 19:58:50 Python

Python

Copy Copied! Full
def freq_letters(s): alph_list = [chr(ord('A') + i) for i in range(26)] cnt_dict = {c: 0 for c in alph_list} upper_s = [c.upper() for c in s if c.upper() in alph_list] for c in upper_s: cnt_dict[c.upper()] += 1 freq_dict = {} for key, cnt in cnt_dict.items(): if not cnt in freq_dict: freq_dict[cnt] = [] freq_dict[cnt].append(key) return freq_dict
RECOMMEND