Genres Whose Tracks Echo the Genre Initial
Problem
A streaming catalog arrives as a DataFrame `catalog` with one row per track, grouped by genre. Find every genre that contains at least 3 tracks AND has at least one track whose title starts with the same letter as the genre name. For each such genre, list all of its track titles joined into a single comma-separated string in alphabetical order, and count how many of its tracks start with the genre's initial letter. Return a DataFrame with columns genre, tracklist and initial_match_count, ordered by initial_match_count descending, then genre.
Input data
Example rows — the live problem includes the full dataset.
| genre | track |
|---|---|
| Nu Disco | Neon Nights |
| Nu Disco | Nova Pulse |
| Nu Disco | Bassline Drift |
| Nu Disco | Retro Glow |
| Chillwave | Sunset Haze |
Expected output
Your answer should return 3 rows with the columns genre, tracklist, initial_match_count.
Starter code (Pandas (Python))
import pandas as pd
def genres_whose_tracks_echo_the_genre_initial(catalog) -> pd.DataFrame:
# Your code here
return catalogSolve 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