Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Artists Tracks Count | Section 3
Python - Music

Sveip for å vise menyen

book
Artists Tracks Count

Oppgave

Swipe to start coding

Complete a function that counts the number of tracks for each artist from a list of tracks. Each track is represented as a dictionary containing various fields, including a track_artist field that indicates the artist of the track.

Inputs:

  • tracks: A list of dictionaries, where each dictionary represents a track and contains at least the following field:
    • track_artist: A string representing the artist of the track.

Steps:

  • Iterate Through Tracks:

    • Loop through each track in the tracks list.
    • For each track, retrieve the track_artist value.
    • If the artist is already in artist_counts, increment their count by 1.
    • If the artist is not in artist_counts, add them with an initial count of 1.
  • Prepare Result: Convert the artist_counts dictionary into a list of dictionaries, where each dictionary contains:

    • artist: The artist's name.
    • count: The number of tracks by that artist

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 4
py

solution.py

py

main.py

Spør AI

expand
ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

book
Artists Tracks Count

Oppgave

Swipe to start coding

Complete a function that counts the number of tracks for each artist from a list of tracks. Each track is represented as a dictionary containing various fields, including a track_artist field that indicates the artist of the track.

Inputs:

  • tracks: A list of dictionaries, where each dictionary represents a track and contains at least the following field:
    • track_artist: A string representing the artist of the track.

Steps:

  • Iterate Through Tracks:

    • Loop through each track in the tracks list.
    • For each track, retrieve the track_artist value.
    • If the artist is already in artist_counts, increment their count by 1.
    • If the artist is not in artist_counts, add them with an initial count of 1.
  • Prepare Result: Convert the artist_counts dictionary into a list of dictionaries, where each dictionary contains:

    • artist: The artist's name.
    • count: The number of tracks by that artist

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 4
Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Vi beklager at noe gikk galt. Hva skjedde?
some-alt