我有一个wxListBox,其中填充了用户输入的字符串(客户名称)。我必须计算列表中出现次数最多的名字和出现次数最少的名字。我必须使用循环
下面是实际代码与伪代码的混合,但我在逻辑上遇到了问题:
cust_name = ""
for names in range(self.txtListBox.GetCount()):
for compareName in counterList:
if:
names == compareName:
count += 1
else:
add names to counterList
set count to 1
用Python中的循环实现这一点的最佳方法是什么
使用collections.Counter来计算姓名
使用循环,只需调用
Counter.update
如果无法导入模块,请使用普通dict:
相关问题 更多 >
编程相关推荐