首页 > 编程语言 >已知列表data中有若干字符串,要求编写程序,对data中的字符串进行过滤,只输出重复字符不超过一半的字符串。

已知列表data中有若干字符串,要求编写程序,对data中的字符串进行过滤,只输出重复字符不超过一半的字符串。

时间:2023-03-12 11:24:05浏览次数:32  
标签:count 编写程序 max 字符串 filtered counts data

data = ['abcd', 'aaa', 'aabbcc', 'abc', 'abccba', 'aabbccddee']

filtered_data = []

for s in data:
counts = {}
for c in s:
counts[c] = counts.get(c, 0) + 1
max_count = max(counts.values())
if max_count <= len(s) / 2:
filtered_data.append(s)

print(filtered_data)

标签:count,编写程序,max,字符串,filtered,counts,data
From: https://www.cnblogs.com/DF696/p/17207811.html

相关文章