Skip to content

Instantly share code, notes, and snippets.

@dev4Fun
Created September 10, 2020 03:24
Show Gist options
  • Save dev4Fun/09d9c02978195b7c90ef9d23f063caf6 to your computer and use it in GitHub Desktop.
Save dev4Fun/09d9c02978195b7c90ef9d23f063caf6 to your computer and use it in GitHub Desktop.
from collections import defaultdict
class PostStats:
def __init__(self):
self.liked_count = 0
self.skipped_count = 0
class _PostTracker:
def __init__(self):
self.posts = {}
self.like_by_user_id = defaultdict(int)
self.liked_count = 0
self.skipped_count = 0
def liked_post(self, post):
self.posts.get(post, PostStats()).liked_count += 1
self.like_by_user_id[post.owner_id] += 1
self.liked_count += 1
def skipped_post(self, post):
self.posts.get(post, PostStats()).skipped_count += 1
self.skipped_count += 1
@property
def stats(self):
return f"Liked: {self.liked_count}, skipped: {self.skipped_count}"
post_tracker = _PostTracker()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment