A billing feed sends event records as dicts. Fields can be missing or None, and the feed mixes in test traffic.
Write select_events(events, min_amount, countries) that returns the "id" of every event that passes all of these rules, in input order:
- •it is not test traffic:
"is_test" is True only for test events; a missing or None "is_test" means a real event; - •its
"type" is exactly "purchase" or "refund"; - •it has an
"amount" (present and not None) whose size is at least min_amount — refunds carry negative amounts, so a refund of -80 passes a min_amount of 50; - •it has a
"country" (present and not None) that is in countries once surrounding spaces are removed and it's upper-cased. countries holds upper-case codes such as {"GB", "US"}.
A record that fails a rule is skipped — the function must never raise because a field is missing or None.
Python 3.13 in your browser — the standard library plus pandas and numpy; no pip installs.