-
Notifications
You must be signed in to change notification settings - Fork 254
Meme Trend Identification
Raymond Chen edited this page Sep 1, 2024
·
4 revisions
Unit 4 Session 1 Standard (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
-
Q: What is the structure of the input?
- A: The input is a list of dictionaries, where each dictionary contains keys such as
""creator""
and""text""
.
- A: The input is a list of dictionaries, where each dictionary contains keys such as
-
Q: What is the output?
- A: The output is a dictionary where the keys are creators' names and the values are the number of memes they have created.
-
Q: What should the function return if the input list is empty?
- A: The function should return an empty dictionary.
-
Q: Are there any constraints on the input, such as the presence of the ""creator"" key in each dictionary?
- A: It is assumed that each dictionary in the list will have a
""creator""
key with a corresponding value.
- A: It is assumed that each dictionary in the list will have a
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Iterate over each dictionary in the input list, extract the value associated with the ""creator""
key, and update a count in a dictionary to track the number of memes each creator has made.
1) Initialize an empty dictionary called `creator_count`.
2) For each dictionary (meme) in the input list:
a) Extract the value associated with the `""creator""` key.
b) If the creator is already in `creator_count`, increment their count by 1.
c) If the creator is not in `creator_count`, add them with a count of 1.
3) Return the `creator_count` dictionary as the output.
**⚠️ Common Mistakes**
- Forgetting to initialize the creator count correctly when encountering a creator for the first time.
- Assuming that the `""creator""` key will always be present in the dictionaries without verifying.
def count_meme_creators(memes):
creator_count = {}
for meme in memes:
creator = meme[""creator""]
if creator in creator_count:
creator_count[creator] += 1
else:
creator_count[creator] = 1
return creator_count