diff --git a/recommendation_engine.py b/recommendation_engine.py index c2d921a..bb99180 100644 --- a/recommendation_engine.py +++ b/recommendation_engine.py @@ -65,7 +65,8 @@ class Engine: # Count tags for the user count = defaultdict(lambda: 0) for event in user.get('events', []): - count[event['data']['product']] += 1 + if event.get('data', {}).get('product'): + count[event['data']['product']] += 1 # For each tag in playlist, increment score by count for playlist in playlists: score[playlist['name']] = random.random()