AnalystPath

Mutual Translation Routes

PandasMediumMid level~10 min

Problem

DataFrame `route` has columns `src` and `dst`, one row per directed route. A pair is mutual when a distinct row exists for both directions: row (a -> b) and a different row (b -> a). This requires two separate rows, so a self-loop (x -> x) is mutual only when it appears at least twice. Report each mutual pair once, normalized so `src <= dst`.

Return columns `src`, `dst`, sorted by `src` then `dst`.

Input data

Example rows — the live problem includes the full dataset.

route
srcdst
1020
2010
3040
5050
5050

Expected output

Your answer should return 2 rows with the columns src, dst.

Starter code (Pandas (Python))

import pandas as pd

def mutual_translation_routes(route) -> pd.DataFrame:
    # Your code here
    return route

Solve 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

Related Pandas questions