Routes, Not Directions

Python for AIHard+10 XP+10

Routes, Not Directions

A bus company logs every trip as a tuple (from_city, to_city). It wants to know how many different routes it runs.

A route is a pair of cities, and direction doesn't matter:

  • ("Leeds", "York") and ("York", "Leeds") are the same route.
  • A trip that starts and ends in the same city, like ("York", "York"), isn't a route at all. Ignore it.

Task: write count_routes(trips). Return the number of different routes. An empty list gives 0.

Examples

trips = [("Leeds", "York"), ("York", "Leeds"), ("York", "Hull")]
returns 2
trips = [("York", "York")]
returns 0

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run