Codepath

NFT Name Extractor

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 names (strings) extracted from each dictionary in the input list.
  • Q: What should the function return if the input list is empty?

    • A: The function should return an empty list.
  • Q: Are there any constraints on the input, such as the presence of the "name" key in each dictionary?

    • A: It is assumed that each dictionary in the list will have a "name" key with a corresponding value.

P-lan

Plan the solution with appropriate visualizations and pseudocode.

General Idea: Iterate over each dictionary in the input list, extract the value associated with the "name" key, and append it to a new list that will be returned as the output.

1) Initialize an empty list called `nft_names`.
2) For each dictionary (nft) in the input list:
   a) Extract the value associated with the "name" key.
   b) Append this value to the `nft_names` list.
3) Return the `nft_names` list as the output.

**⚠️ Common Mistakes**

- Forgetting to handle cases where the input list is empty.
- Assuming that the "name" key will always be present in the dictionaries without verifying.

I-mplement

def extract_nft_names(nft_collection):
    nft_names = []
    for nft in nft_collection:
        nft_names.append(nft["name"])
    return nft_names
Fork me on GitHub