我正在为Deezer编写一组工具。我正在处理的专辑将在指定的播放列表中循环播放,如果在多个播放列表中找到了一张专辑,则应报告。
我已经尝试过各种变体,可以使用数组和字典,但是它从来没有达到我预期的工作方式。
for count in range(len(playlists_tracks)):
album_name = playlists_tracks[count]["album"]["title"]
album_id = playlists_tracks[count]["album"]["id"]
if album_name not in albums:
albums[album_name] = playlist_name
playlist_dupe[album_name] = playlist_name
print ("New: " + album_name + " in " + playlist_name)
elif album_name in albums and album_name not in playlist_dupe:
playlist_dupe[album_name] = playlist_name
albums_dupe[album_name] = albums[album_name] + " + " + playlist_name
print ("Dupe: " + album_name + " in " + playlist_name)
else:
pass
上面的代码将遍历所有播放列表(在此示例中为三个),但不会向后报告正确的播放列表。专辑“ 1930”应该在播放列表1 + 2 + 3中,但只说1 +3。说专辑之后的专辑在2 + 2中存在(是的,但是不应该输出)。我在pastebin上有完整的代码。
示例:
[('1930', 'Various Artists_Part1 + Various Artists_Part3'), ('4 Women No Cry', 'Various Artists_Part2 + Various Artists_Part2'), ('4 Women No Cry Vol. 3', 'Various Artists_Part2 + Various Artists_Part2')