Search code examples
pythonstringlistspotipy

Convert multiple string to a list in python


I want to get the name of the song from a Spotify playlist for which I am using spotipy library when I print the output it all comes at once I want to get the single name at a time

CODE:

for track in sp.playlist_tracks(playlist_link)["items"]:    
    track_name = track["track"]["name"]
    print(track_name)

OUTPUT


Solution

  • What I understand is that you want to add the text of each line to the list

    my_list = []
    for track in sp.playlist_tracks(playlist_link)["items"]:    
        track_name = track["track"]["name"]
        my_list.append(track_name)
    print(my_list)