From 97adb8a6e8314e1032e635d47861eb0db02be02f Mon Sep 17 00:00:00 2001 From: Bhupesh-V Date: Thu, 4 Jan 2024 16:33:09 +0530 Subject: [PATCH] shift emoji only users into separate list --- user-flair-usage/main.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/user-flair-usage/main.py b/user-flair-usage/main.py index c099006..5bea667 100644 --- a/user-flair-usage/main.py +++ b/user-flair-usage/main.py @@ -25,16 +25,33 @@ subreddit = reddit.subreddit(sub) flair_count = defaultdict(int) # Iterate over all the flairs +emoji_flair_count = 0 +emoji_flair_users = [] for flair in subreddit.flair(limit=None): - flair_count[flair['flair_text']] += 1 + f = flair['flair_text'].strip() + + if f.startswith(":") and f.endswith(":"): + emoji_flair_count += 1 + emoji_flair_users.append( + dict( + user=flair['user'], + flair_text=f + ) + ) + else: + flair_count[flair['flair_text'].strip()] += 1 # Convert the dictionary to a list of tuples and sort it by the count sorted_flairs = sorted(flair_count.items(), key=lambda x: x[1], reverse=True) -# Print the sorted list of flairs and their counts -for flair, count in sorted_flairs: - print(f"Flair: {flair}, Count: {count}") +# # Print the sorted list of flairs and their counts +# for flair, count in sorted_flairs: +# print(f"Flair: {flair}, Count: {count}") +for user in emoji_flair_users: + print(user) # Calculate and print the total count of all flairs total_count = sum(flair_count.values()) -print(f"Total count of all flairs: {total_count}") \ No newline at end of file +print(f"Total count of non-emoji flairs: {total_count}") +print(f"Total count of emoji only flairs: {emoji_flair_count}") +print(f"Total count of user-flairs: {total_count + emoji_flair_count}") \ No newline at end of file