Codepath

Identify Popular Creators

Unit 4 Session 1 Standard (Click for link to problem statements)

U-nderstand

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 represents an NFT and contains keys such as "name", "creator", and "value".
  • Q: What is the output?

    • A: The output is a list of creator names (strings) who have created more than one NFT in the collection.
  • Q: What should the function return if no creators are considered "popular"?

    • A: The function should return an empty list.
  • 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.

P-lan

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.

I-mplement

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
Fork me on GitHub