1

I'm trying to get the last 4 songs I've listened to from last_fm using pylast.

So far I have this code but os returning just one song:

def get_recents(self, max_results):
        recents = self.user.get_recent_tracks(max_results)
        for song in recents:
            return str(song.track)

1 Answers1

2

The return statement will break out of your loop immediately, meaning it will only execute once. Just return a list of songs using a list comprehension:

def get_recents(self, max_results):
    recents = self.user.get_recent_tracks(max_results)
    return [str(x) for x in recents[:4]]
Jonah Bishop
  • 12,279
  • 6
  • 49
  • 74