Your question is Code Snippet Issue Identification. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
PitchBook ingests funding round records from multiple data partners and merges them into one company funding history before analysts see them. The function below is producing funding histories with duplicate rounds and rounds in the wrong order. Identify the potential issues in this snippet of code.
def merge_funding_rounds(records):
cleaned = []
for r in records:
r["round_date"] # string like "2023-05-01" or "05/01/2023" depending on source
amount_usd = r["amount"]
is_duplicate = False
for c in cleaned:
if c["amount"] == amount_usd and c["round_date"] == r["round_date"]:
is_duplicate = True
if not is_duplicate:
cleaned.append(r)
for r in records:
if r.get("amount") is None:
records.remove(r)
cleaned.sort(key=lambda r: r["round_date"])
return cleaned
Walk through what could go wrong here and why.