Thursday 15 September 2011

spyder - Python writing codes to get the most active customer and least customer -



spyder - Python writing codes to get the most active customer and least customer -

we asked design gui calculate active , to the lowest degree active customers. there 2 buttons @ bottom calculate , to the lowest degree active customer. there results area display result of pressing 2 buttons.

there list box, , 2 buttons under it. names show in list box. instance, when come in "sam" in textctrl number one, , click add together client button. sam appear in list box. after come in different or same names few times. list names list box. instance, there 3 "sam"s , 2 "justin"s in list box. when click "most active button", name sam appear in result box. when click to the lowest degree active button, name justin appear in result box.

i defined add together client button, have no thought how define buttons calculating active , to the lowest degree active customers. told me need utilize count function, not sure how it.

here got far:

def addcustomer(self,event): try: name=str(self.m_textctrl1.value) self.m_listbox1.append(str(name)) except: wx.messagebox("this can't empty.") def mostactive(self,parent):

can help me on next step? give thanks you! p.s. name of result box m_textctrl2 name of list box m_listbox1

collections.counter has convenient method .most_common getting mutual items in list:

>>> collections import counter >>> namescounter = counter(['rod', 'rod', 'rod', 'jane', 'jane', 'freddie']) >>> namescounter.most_common(1) [('rod', 3)]

the to the lowest degree mutual items obtained this:

>>> [(k, min(namescounter.values())) k, v in namescounter.iteritems() if v == min(namescounter.values())] [('freddie', 1)]

... though bit un-pythonic.

python spyder wxformbuilder

No comments:

Post a Comment