Created
September 10, 2020 03:24
-
-
Save dev4Fun/09d9c02978195b7c90ef9d23f063caf6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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