title: Getting top albums from last.fm
body: <p>Im getting the top artists from a specific country from lastfm api. Im getting the name of each artist and store in the <code>artists{}</code> with success with:</p>
  
  <pre><code>import requests
  
  api_key = "0929f1144e531702a5563c887cbbade0"
  
  ID = 0
  artists = {}
  
  for i in range(1, 3):
  
      artists_response = requests.get('http://ws.audioscrobbler.com/2.0/?method=geo.gettopartists&amp;country=spain&amp;format=json&amp;page=' + str(i) + '&amp;api_key=' + api_key)
      artists_data = artists_response.json()
  
      for artist in artists_data["topartists"]["artist"]:
  
          name = artist["name"]
  
          artists[ID] = {}
          artists[ID]['ID'] = ID
          artists[ID]['name'] = name
          ID += 1
  </code></pre>
  
  <p>But now for each artist I want to get the top5 albums and store in the <code>albums{},</code> the artist name, the artist id, the name the album, and the url of the album. </p>
  
  <p>For example for each artist, I want to get one record for each album of the top5 albums like this:</p>
  
  <pre><code> "Artist": "U2", "ID": 175, "ArtistID": 10, "Title": Achtung    Baby",  
   "Image": "https://lastfm-img2.akamaized.net/i/u/174s/a482040d21924ddacd5fe75dedbb1ef2.png"},
   "URL": "https://www.last.fm/music/U2/Achtung+Baby"}, "487": {"Date": "2004-01-01"
  
   "Artist": "U2", "ID": 176, "ArtistID": 10, "Description": "None", "Title": "Boy", 
  
  
   ... and then the same for the other 3 albums of the top5
  </code></pre>
  
  <p>Im doing this with the code below, but its not working correctly. The artistId appears always as "0" and it only appears the 5 albums of the first artist. Do you know where is the issue?</p>
  
  <pre><code>albums = {}
  
  for i,v in artists.items():
      chosen = artists[i]['name'].replace(" ", "+")
      topalbums_response = requests.get('http://ws.audioscrobbler.com/2.0/?method=artist.gettopalbums&amp;format=json&amp;artist=' + chosen + '&amp;api_key=' + api_key + '&amp;limit=5')
      albums_data = topalbums_response.json()
  
      for album in albums_data['topalbums']['album']:
  
          name = album["name"]
          url = album["url"]
  
          albums[ID] = {}
          albums[ID]['ID'] = ID
          albums[ID]['artist'] = artists[i]['name']
          albums[ID]['artistID'] = artists[i]['ID']
          albums[ID]['name'] = name
          albums[ID]['url'] = url
  
          for image in album['image']:
              if (image["size"] == "large"):
                  if (image["size"] is not None):
                      image = image["#text"]
                      albums[ID]['image'] = image
  
          ID += 1
  
          print(albums)
  </code></pre>