Advertisement
Guest User

Untitled

a guest
Jul 6th, 2020
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. class Recommender(object):
  2.  
  3.     def get_product_key(self, id):
  4.         return 'product:{}:purchased_with'.format(id)
  5.  
  6.     def products_bought(self, products):
  7.         product_ids = [p.id for p in products]
  8.         for product_id in product_ids:
  9.             for with_id in product_ids:
  10.                 if product_id != with_id:
  11.                     r.zincrby(self.get_product_key(product_id),
  12.                               with_id,
  13.                               amount=1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement