Valid Message Routing Keys
Problem
You are given one DataFrame `routing_keys` with columns `record_id` and `handle`, where a handle is shaped like `local@server.net`.
A handle is **valid** only when ALL of these hold: it contains exactly one `@`; the part before the `@` uses only letters, digits, or underscores; the part after the `@` (the server) uses only letters; and it ends in `.net` (lowercase). Missing or empty handles are never valid.
Return columns `record_id` and `handle` for every valid routing key, ordered by `record_id` ascending.
Input data
Example rows — the live problem includes the full dataset.
| record_id | handle |
|---|---|
| 1 | sales_north@hub.net |
| 2 | finance#hub.net |
| 3 | support@hub.io |
| 4 | logistics@depot.net |
| 5 | intake@local |
Expected output
Your answer should return 2 rows with the columns record_id, handle.
Starter code (Pandas (Python))
import pandas as pd
def valid_routing_keys(routing_keys) -> pd.DataFrame:
# Your code here
return routing_keysSolve this Pandas question free
Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock