Throwing Methods Around : Class Definition : Class PYTHON TUTORIALS


PYTHON TUTORIALS » Class » Class Definition »

 

Throwing Methods Around


class FoodExpert:
   def init(self):
      self.goodFood = []

   def addGoodFood(self, food):
      self.goodFood.append(food)

   def likes(self, x):
      return x in self.goodFood

   def prefers(self, x, y):
      x_rating = self.goodFood.index(x)
      y_rating = self.goodFood.index(y)
      if x_rating > y_rating:
         return y
      else:
         return 

f = FoodExpert()
f.init()
map(f.addGoodFood, ['A''B''C''D''E'])
print f.goodFood

menu = ['a''b''c']
rec = filter(f.likes, menu)
print rec



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Class
» Class Definition