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?
Q: What is the output?
Q: What should the function return if no creators are considered "popular"?
Q: Are there any constraints on the input, such as the presence of the "creator" key in each dictionary?
Plan the solution with appropriate visualizations and pseudocode.
General Idea: We need to count the number of NFTs each creator has made and then identify the creators who have created more than one NFT.
1) Initialize an empty dictionary called `creator_count` to store the count of NFTs per creator.
2) Iterate through each NFT in the collection:
a) Extract the value associated with the "creator" key.
b) Increment the count for this creator in the `creator_count` dictionary.
3) After iterating through the collection, create a list `popular_creators` of all creators who have more than one NFT.
4) Return the `popular_creators` list as the output.
**⚠️ Common Mistakes**
- Forgetting to initialize the creator's count in the dictionary.
- Not correctly identifying creators with more than one NFT.
def identify_popular_creators(nft_collection):
creator_count = {}
for nft in nft_collection:
creator = nft["creator"]
if creator in creator_count:
creator_count[creator] += 1
else:
creator_count[creator] = 1
popular_creators = [creator for creator, count in creator_count.items() if count > 1]
return popular_creators