I've created a GUI using wxFormBuilder that should allow a user to enter the names of "visitors to a business" into a list and then click one of two buttons to return the most frequent and least frequent visitors to the business.
I created an earlier version that, unfortunately, gave me the range of visitors, rather than the name of the most/least frequent visitor. I've attached a screenshot of the GUI I've created to help add a little clarity to the issue ( https://i.stack.imgur.com/6GHbK.jpg ).
A new code version takes a different tack than the earlier version, and I can't get it to throw anything. Instead, I keep receiving this error:
ValueError: max() arg is an empty sequence
In relation to this line:
self.txtResults.Value = k.index(max(v))
import wx
import myLoopGUI
import commandsclass MyLoopFrame(myLoopGUI.MyFrame1):def __init__(self, parent):myLoopGUI.MyFrame1.__init__(self, parent)def clkAddData(self,parent):if len(self.txtAddData.Value) != 0:try:myname = str(self.txtAddData.Value)self.listMyData.Append(str(myname))except:wx.MessageBox("This has to be a name!") else:wx.MessageBox("This can't be empty")def clkFindMost(self, parent):self.listMyData = []unique_names = set(self.listMyData)frequencies = {}for name in unique_names:if frequencies.get[name]:frequencies[name] += 1else:frequencies[name] = 0v = list(frequencies.values())k = list(frequencies.keys())self.txtResults.Value = k.index(max(v))def clkFindLeast(self, parent):unique_names = set(self.listMyData)frequencies = {}for name in unique_names:if frequencies.get(name):frequencies[name] += 1else:frequencies[name] = 0v = list(frequencies.values())k = list(frequencies.keys())self.txtResults.Value = k.index(min(v))myApp = wx.App(False)
myFrame = MyLoopFrame(None)
myFrame.Show()
myApp.MainLoop()