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 the input list is empty?
Q: Are there any constraints on the input, such as the presence of the "name" key in each dictionary?
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.
def extract_nft_names(nft_collection):
nft_names = []
for nft in nft_collection:
nft_names.append(nft["name"])
return nft_names