class Calculate: 
      def __init__(self): 
        self.prior = {}   = {}   
        self.count = 0   
      def add(self, cls, obs): 
        self.prior[cls] = self.prior.get(cls, 0) + 1 
        for idx, val in enumerate(obs): 
            key = cls, idx, val 
  [key] =, 0) + 1 
        self.count += 1 
      def discr(self, cls, obs): 
        result = self.prior[cls]/self.count 
        for idx, val in enumerate(obs): 
            freq =, idx, val), 0) 
            result *= freq/self.prior[cls] 
        return result 
      def classify(self, obs): 
        candidates = [(self.discr(c, obs), c) for c in self.prior] 
        return max(candidates)[1] 

Dear Group,
If anyone of the learned members help me to understand the above code:
Apology for the indentation errors.

There is obviously something missing: the creation of the list, obs. Given that, the method, add(), updates the values in prior and total for each element of obs. The method, discr(), looks like it's updating something like a grade point average for each element in obs. The method, classify(), looks like it should return the highest grade point average (if that's really what discr() returns) for each element in prior, only I don't think the "[1]" is right.