Average Tempo by Key
Swipe to start coding
Complete a function that calculates the average tempo (in beats per minute, BPM) of tracks for each musical key. Each track is represented as a dictionary containing various fields, including tempo
and key
.
Inputs:
tracks
: A list of dictionaries, where each dictionary represents a track and contains at least the following fields:tempo
: A float representing the tempo of the track in BPM.key
: An integer representing the musical key of the track, ranging from 0 to 11.
Steps:
-
Iterate Through Keys:
- Loop through each musical key from 0 to 11.
- For each key, create a list
key_tempos
that contains thetempo
of tracks with the current key.
-
Calculate Average Tempo:
- If
key_tempos
is not empty, calculate the average tempo by summing the tempos and dividing by the number of tempos. - Store the calculated average tempo in
average_tempos
with the current key as the dictionary key.
- If
Solution
Merci pour vos commentaires !
solution.py
main.py
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion
Résumer ce chapitre
Expliquer le code dans file
Expliquer pourquoi file ne résout pas la tâche
Awesome!
Completion rate improved to 5.56
Average Tempo by Key
Glissez pour afficher le menu
Swipe to start coding
Complete a function that calculates the average tempo (in beats per minute, BPM) of tracks for each musical key. Each track is represented as a dictionary containing various fields, including tempo
and key
.
Inputs:
tracks
: A list of dictionaries, where each dictionary represents a track and contains at least the following fields:tempo
: A float representing the tempo of the track in BPM.key
: An integer representing the musical key of the track, ranging from 0 to 11.
Steps:
-
Iterate Through Keys:
- Loop through each musical key from 0 to 11.
- For each key, create a list
key_tempos
that contains thetempo
of tracks with the current key.
-
Calculate Average Tempo:
- If
key_tempos
is not empty, calculate the average tempo by summing the tempos and dividing by the number of tempos. - Store the calculated average tempo in
average_tempos
with the current key as the dictionary key.
- If
Solution
Merci pour vos commentaires !
Awesome!
Completion rate improved to 5.56solution.py
main.py