2
def lowEnergy():

    tids = []
    # get songs by recommendation
    results = sp.recommendations(seed_artists = [artist['id']])

    #retrieve uris for songs
    for track in results['tracks']:
        tids.append(track['uri'])

    #get audio_features
    features = sp.audio_features(tids)

    #pick energies
    energy = [x['energy'] for x in features]

    #here I filter out low energy values
    low_energy = [x for x in energy if x < 0.5]

    #get track names
    track_names = [sp.track(uri)['name'] for uri in tids]

现在我想通过低于 0.5 的能量值过滤掉轨道名称,如下所示

track name1 - 0.49 track name2 - 0.34

等等。

但我在这里挣扎......我该如何实现这一目标?谢谢

4

1 回答 1

0

未测试,但希望它有效。

for i, e in enumerate(energy):
    if e < 0.5:
        track_name = sp.track(tids[i])['name']
        print("{} - {}".format(track_name, e))
于 2016-08-09T03:48:49.407 回答