bharatverse11's picture
Update utils.py
8847fc8 verified
raw
history blame contribute delete
489 Bytes
def deduplicate_tracks(tracks):
seen = set()
unique = []
for t in tracks:
if t["id"] not in seen:
seen.add(t["id"])
unique.append(t)
return unique
def diversify_tracks(tracks):
result = []
artist_count = {}
for t in tracks:
artist = t["artists"][0]["name"]
count = artist_count.get(artist, 0)
if count < 2:
result.append(t)
artist_count[artist] = count + 1
return result