题解 | #删除字符串中出现次数最少的字符#用pytho字典
删除字符串中出现次数最少的字符
https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
s = str(input()) dic = dict() #用字典记录每个字符出现的次数 for c in s: if c not in dic: dic[c] = 1 else: dic[c] += 1 ans = '' #对出现的次数进行排序,最少的记录下来,num sortdic = sorted(dic.values()) num = int(sortdic[0]) for i in s: 遍历字符串,如果字典中存的值不等于记录的num,就拼接到空字符串中,一直累加拼接,最后就是答案 if dic[i] != num: ans += i print(ans)