Problem
Given an array of event record strings records, implement a Python function that returns a new array containing only valid transformed records. Each input string has the form "key:value". A record is valid if it contains exactly one colon, the key is non-empty after trimming spaces, and the value is non-empty after trimming spaces. For each valid record, return it as "KEY=value", where the key is uppercased and duplicate keys keep only their last valid value while preserving the key's first appearance order.
Constraints
- 1 <= len(records) <= 10^4
- 0 <= len(records[i]) <= 10^3
- Each record is a Python string
- Preserve first appearance order of valid keys
- Ignore invalid records instead of raising errors
Function Signature
def transform_records(records):
Practicing as: Data Engineer interview at Rolls-RoyceHi, I'll play your Rolls-Royce interviewer for the Data Engineer role. Answer the question above like we're in the room, and I'll respond the way a real interviewer would.
You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.
