In [1]:
import requests
response = requests.get('https://api.spotify.com/v1/search?query=lil&type=artist&country=US&limit=50')
data = response.json()
# data['artists'].keys()
# data['artists']['items'][0]

In [2]:
data['artists']['items'][0]


Out[2]:
{'external_urls': {'spotify': 'https://open.spotify.com/artist/55Aa2cqylxrFIXC767Z865'},
 'followers': {'href': None, 'total': 2623924},
 'genres': ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music'],
 'href': 'https://api.spotify.com/v1/artists/55Aa2cqylxrFIXC767Z865',
 'id': '55Aa2cqylxrFIXC767Z865',
 'images': [{'height': 1239,
   'url': 'https://i.scdn.co/image/cf012139c3b8681b46a66bae70558a8a336ab231',
   'width': 1000},
  {'height': 793,
   'url': 'https://i.scdn.co/image/fffd48d60e27901f6e9ce99423f045cb2b893944',
   'width': 640},
  {'height': 248,
   'url': 'https://i.scdn.co/image/bf03141629c202e94b206f1374a39326a9d8c6ca',
   'width': 200},
  {'height': 79,
   'url': 'https://i.scdn.co/image/521f99f2469883b8806a69a3a2487fdd983bd621',
   'width': 64}],
 'name': 'Lil Wayne',
 'popularity': 86,
 'type': 'artist',
 'uri': 'spotify:artist:55Aa2cqylxrFIXC767Z865'}

In [3]:
#1 50 Lils and their popularity

items = data['artists']['items']
for item in items:
    print (item['name'], item['popularity'])


Lil Wayne 86
Lil Yachty 72
Lil Uzi Vert 72
Lil Dicky 68
Boosie Badazz 67
Lil Jon 72
King Lil G 61
Lil Durk 60
Lil Jon & The East Side Boyz 60
Lil Bibby 54
G Herbo 53
Lil Rob 50
Lil Reese 50
Lil Keke 48
Bow Wow 57
Lil Scrappy 48
Lil Wyte 50
Lil Blood 45
Lil Snupe 45
Lil Mama 45
Lil B 44
Lil' Kim 62
Lil Cuete 40
Lil Phat 39
Lil Debbie 43
Lil Twist 39
Lil Trill 37
Lil Twon 38
Lil AJ 37
Lil Lonnie 37
Lil Boom 35
Lil Goofy 35
Mr. Lil One 36
Lil Haiti 36
Lil Flash 38
Lil Kesh 39
Lil Cray 35
Lil Silva 43
Lil Rue 34
Lil Eddie 41
Lil Yase 33
Lil Wayne, DJ Drama 35
Lil Suzy 34
Lil Mouse 34
Lil C 33
Lil Rick 39
Lil June 32
Lil E 34
Lil Fate 34
Lil' Flip 49

2) What genres are most represented in the search results? Edit your previous printout to also display a list of their genres in the format "GENRE_1, GENRE_2, GENRE_3". If there are no genres, print "No genres listed". Tip: "how to join a list Python" might be a helpful search


In [5]:
items = data['artists']['items']
for item in items:
    if len(item['genres'])==0:
        print("No genres listed")
    else:
        print(','.join(item['genres']))


dirty south rap,pop rap,southern hip hop,trap music
No genres listed
No genres listed
No genres listed
No genres listed
crunk,dirty south rap,southern hip hop
No genres listed
No genres listed
No genres listed
No genres listed
No genres listed
chicano rap,latin hip hop
No genres listed
No genres listed
hip pop,pop rap
crunk,dirty south rap,southern hip hop,trap music
juggalo
No genres listed
No genres listed
hip pop
No genres listed
hip pop
chicano rap
No genres listed
No genres listed
jerk
deep trap
No genres listed
No genres listed
No genres listed
No genres listed
No genres listed
chicano rap
No genres listed
No genres listed
No genres listed
No genres listed
No genres listed
No genres listed
No genres listed
No genres listed
No genres listed
freestyle
No genres listed
No genres listed
soca
No genres listed
No genres listed
No genres listed
crunk,dirty south rap

In [8]:
# AGGREGATION PROBLEM
all_genres = []

# THE LOOP
for item in items:
    print ("All genres so far: ", all_genres)
    # THE CONDITIONAL
    print ("Current artist has: ", item['genres'])
    all_genres = all_genres + item['genres']
print ('++++++++++++++++++++++++++++++++')
print ("All final genres: ", all_genres)


All genres so far:  []
Current artist has:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music']
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music']
Current artist has:  ['crunk', 'dirty south rap', 'southern hip hop']
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop']
Current artist has:  ['chicano rap', 'latin hip hop']
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop']
Current artist has:  ['hip pop', 'pop rap']
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap']
Current artist has:  ['crunk', 'dirty south rap', 'southern hip hop', 'trap music']
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music']
Current artist has:  ['juggalo']
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo']
Current artist has:  ['hip pop']
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop']
Current artist has:  ['hip pop']
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop']
Current artist has:  ['chicano rap']
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap']
Current artist has:  ['jerk']
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk']
Current artist has:  ['deep trap']
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap']
Current artist has:  ['chicano rap']
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap', 'chicano rap']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap', 'chicano rap']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap', 'chicano rap']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap', 'chicano rap']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap', 'chicano rap']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap', 'chicano rap']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap', 'chicano rap']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap', 'chicano rap']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap', 'chicano rap']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap', 'chicano rap']
Current artist has:  ['freestyle']
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap', 'chicano rap', 'freestyle']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap', 'chicano rap', 'freestyle']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap', 'chicano rap', 'freestyle']
Current artist has:  ['soca']
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap', 'chicano rap', 'freestyle', 'soca']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap', 'chicano rap', 'freestyle', 'soca']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap', 'chicano rap', 'freestyle', 'soca']
Current artist has:  []
All genres so far:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap', 'chicano rap', 'freestyle', 'soca']
Current artist has:  ['crunk', 'dirty south rap']
++++++++++++++++++++++++++++++++
All final genres:  ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap', 'chicano rap', 'freestyle', 'soca', 'crunk', 'dirty south rap']

In [12]:
for genre in all_genres:
    genre_count = all_genres.count(genre)
    print (genre, genre_count)
unique_genres = set(all_genres)
print ('+++++++++++++++++++++++')
for genre in unique_genres:
    genre_count = all_genres.count(genre)
    print(genre, genre_count)
print ("dirty south rap is the most represented genre")


dirty south rap 4
pop rap 2
southern hip hop 3
trap music 2
crunk 3
dirty south rap 4
southern hip hop 3
chicano rap 3
latin hip hop 1
hip pop 3
pop rap 2
crunk 3
dirty south rap 4
southern hip hop 3
trap music 2
juggalo 1
hip pop 3
hip pop 3
chicano rap 3
jerk 1
deep trap 1
chicano rap 3
freestyle 1
soca 1
crunk 3
dirty south rap 4
+++++++++++++++++++++++
deep trap 1
freestyle 1
hip pop 3
crunk 3
pop rap 2
trap music 2
jerk 1
dirty south rap 4
juggalo 1
southern hip hop 3
latin hip hop 1
chicano rap 3
soca 1
dirty south rap is the most represented genre

3) Use a for loop to determine who BESIDES Lil Wayne has the highest popularity rating. Is it the same artist who has the largest number of followers?


In [22]:
# popularity
items = data['artists']['items']
# AGGREGATION PROBLEM
most_popular_name = ""
most_popular_score = 0
for item in items:
    print ("Looking at", item['name'], "who has popularity of", item['popularity'])
    print ("Comapring", item['popularity'], "to", most_popular_score)
    # THE CONDITIONAL
    if item['popularity'] > most_popular_score:
        if item['name'] == 'Lil Wayne':
            pass
        else:
            most_popular_name = item['name']
            most_popular_score = item['popularity']
    else:
        pass
print ('++++++++++++++++++++')
print (most_popular_name, most_popular_score)


Looking at Lil Wayne who has popularity of 86
Comapring 86 to 0
Looking at Lil Yachty who has popularity of 72
Comapring 72 to 0
Looking at Lil Uzi Vert who has popularity of 72
Comapring 72 to 72
Looking at Lil Dicky who has popularity of 68
Comapring 68 to 72
Looking at Boosie Badazz who has popularity of 67
Comapring 67 to 72
Looking at Lil Jon who has popularity of 72
Comapring 72 to 72
Looking at King Lil G who has popularity of 61
Comapring 61 to 72
Looking at Lil Durk who has popularity of 60
Comapring 60 to 72
Looking at Lil Jon & The East Side Boyz who has popularity of 60
Comapring 60 to 72
Looking at Lil Bibby who has popularity of 54
Comapring 54 to 72
Looking at G Herbo who has popularity of 53
Comapring 53 to 72
Looking at Lil Rob who has popularity of 50
Comapring 50 to 72
Looking at Lil Reese who has popularity of 50
Comapring 50 to 72
Looking at Lil Keke who has popularity of 48
Comapring 48 to 72
Looking at Bow Wow who has popularity of 57
Comapring 57 to 72
Looking at Lil Scrappy who has popularity of 48
Comapring 48 to 72
Looking at Lil Wyte who has popularity of 50
Comapring 50 to 72
Looking at Lil Blood who has popularity of 45
Comapring 45 to 72
Looking at Lil Snupe who has popularity of 45
Comapring 45 to 72
Looking at Lil Mama who has popularity of 45
Comapring 45 to 72
Looking at Lil B who has popularity of 44
Comapring 44 to 72
Looking at Lil' Kim who has popularity of 62
Comapring 62 to 72
Looking at Lil Cuete who has popularity of 40
Comapring 40 to 72
Looking at Lil Phat who has popularity of 39
Comapring 39 to 72
Looking at Lil Debbie who has popularity of 43
Comapring 43 to 72
Looking at Lil Twist who has popularity of 39
Comapring 39 to 72
Looking at Lil Trill who has popularity of 37
Comapring 37 to 72
Looking at Lil Twon who has popularity of 38
Comapring 38 to 72
Looking at Lil AJ who has popularity of 37
Comapring 37 to 72
Looking at Lil Lonnie who has popularity of 37
Comapring 37 to 72
Looking at Lil Boom who has popularity of 35
Comapring 35 to 72
Looking at Lil Goofy who has popularity of 35
Comapring 35 to 72
Looking at Mr. Lil One who has popularity of 36
Comapring 36 to 72
Looking at Lil Haiti who has popularity of 36
Comapring 36 to 72
Looking at Lil Flash who has popularity of 38
Comapring 38 to 72
Looking at Lil Kesh who has popularity of 39
Comapring 39 to 72
Looking at Lil Cray who has popularity of 35
Comapring 35 to 72
Looking at Lil Silva who has popularity of 43
Comapring 43 to 72
Looking at Lil Rue who has popularity of 34
Comapring 34 to 72
Looking at Lil Eddie who has popularity of 41
Comapring 41 to 72
Looking at Lil Yase who has popularity of 33
Comapring 33 to 72
Looking at Lil Wayne, DJ Drama who has popularity of 35
Comapring 35 to 72
Looking at Lil Suzy who has popularity of 34
Comapring 34 to 72
Looking at Lil Mouse who has popularity of 34
Comapring 34 to 72
Looking at Lil C who has popularity of 33
Comapring 33 to 72
Looking at Lil Rick who has popularity of 39
Comapring 39 to 72
Looking at Lil June who has popularity of 32
Comapring 32 to 72
Looking at Lil E who has popularity of 34
Comapring 34 to 72
Looking at Lil Fate who has popularity of 34
Comapring 34 to 72
Looking at Lil' Flip who has popularity of 49
Comapring 49 to 72
++++++++++++++++++++
Lil Yachty 72

In [27]:
data['artists']['items'][0]['followers']['total']


Out[27]:
2623924

In [28]:
# Followers
# popularity
items = data['artists']['items']
# AGGREGATION PROBLEM
artist_most_followers = ""
most_followers = 0
for item in items:
    print ("Looking at", item['name'], "who has", item['followers']['total'], "followers")
    print ("Comapring", item['followers']['total'], "to", most_followers)
    # THE CONDITIONAL
    if item['followers']['total'] > most_followers:
        if item['name'] == 'Lil Wayne':
            pass
        else:
            artist_most_followers = item['name']
            most_followers = item['followers']['total']
    else:
        pass
print ('++++++++++++++++++++')
print (artist_most_followers, most_followers)


Looking at Lil Wayne who has 2623924 followers
Comapring 2623924 to 0
Looking at Lil Yachty who has 37974 followers
Comapring 37974 to 0
Looking at Lil Uzi Vert who has 55211 followers
Comapring 55211 to 37974
Looking at Lil Dicky who has 224765 followers
Comapring 224765 to 55211
Looking at Boosie Badazz who has 220156 followers
Comapring 220156 to 224765
Looking at Lil Jon who has 256052 followers
Comapring 256052 to 224765
Looking at King Lil G who has 64210 followers
Comapring 64210 to 256052
Looking at Lil Durk who has 134097 followers
Comapring 134097 to 256052
Looking at Lil Jon & The East Side Boyz who has 17045 followers
Comapring 17045 to 256052
Looking at Lil Bibby who has 44109 followers
Comapring 44109 to 256052
Looking at G Herbo who has 51481 followers
Comapring 51481 to 256052
Looking at Lil Rob who has 35828 followers
Comapring 35828 to 256052
Looking at Lil Reese who has 23839 followers
Comapring 23839 to 256052
Looking at Lil Keke who has 18746 followers
Comapring 18746 to 256052
Looking at Bow Wow who has 118546 followers
Comapring 118546 to 256052
Looking at Lil Scrappy who has 27080 followers
Comapring 27080 to 256052
Looking at Lil Wyte who has 31106 followers
Comapring 31106 to 256052
Looking at Lil Blood who has 5524 followers
Comapring 5524 to 256052
Looking at Lil Snupe who has 33987 followers
Comapring 33987 to 256052
Looking at Lil Mama who has 21110 followers
Comapring 21110 to 256052
Looking at Lil B who has 224 followers
Comapring 224 to 256052
Looking at Lil' Kim who has 70228 followers
Comapring 70228 to 256052
Looking at Lil Cuete who has 15580 followers
Comapring 15580 to 256052
Looking at Lil Phat who has 5331 followers
Comapring 5331 to 256052
Looking at Lil Debbie who has 14522 followers
Comapring 14522 to 256052
Looking at Lil Twist who has 14832 followers
Comapring 14832 to 256052
Looking at Lil Trill who has 2123 followers
Comapring 2123 to 256052
Looking at Lil Twon who has 318 followers
Comapring 318 to 256052
Looking at Lil AJ who has 897 followers
Comapring 897 to 256052
Looking at Lil Lonnie who has 1332 followers
Comapring 1332 to 256052
Looking at Lil Boom who has 172 followers
Comapring 172 to 256052
Looking at Lil Goofy who has 1340 followers
Comapring 1340 to 256052
Looking at Mr. Lil One who has 4744 followers
Comapring 4744 to 256052
Looking at Lil Haiti who has 679 followers
Comapring 679 to 256052
Looking at Lil Flash who has 1763 followers
Comapring 1763 to 256052
Looking at Lil Kesh who has 1660 followers
Comapring 1660 to 256052
Looking at Lil Cray who has 985 followers
Comapring 985 to 256052
Looking at Lil Silva who has 9431 followers
Comapring 9431 to 256052
Looking at Lil Rue who has 3286 followers
Comapring 3286 to 256052
Looking at Lil Eddie who has 1623 followers
Comapring 1623 to 256052
Looking at Lil Yase who has 1129 followers
Comapring 1129 to 256052
Looking at Lil Wayne, DJ Drama who has 12850 followers
Comapring 12850 to 256052
Looking at Lil Suzy who has 5889 followers
Comapring 5889 to 256052
Looking at Lil Mouse who has 16305 followers
Comapring 16305 to 256052
Looking at Lil C who has 1705 followers
Comapring 1705 to 256052
Looking at Lil Rick who has 1829 followers
Comapring 1829 to 256052
Looking at Lil June who has 1396 followers
Comapring 1396 to 256052
Looking at Lil E who has 130 followers
Comapring 130 to 256052
Looking at Lil Fate who has 110 followers
Comapring 110 to 256052
Looking at Lil' Flip who has 19889 followers
Comapring 19889 to 256052
++++++++++++++++++++
Lil Jon 256052

4) print a list of Lil's that are more popular than Lil' Kim.


In [29]:
items = data['artists']['items']
for item in items:
    if item['name'] == "Lil' Kim":
        print (item['name'], item['popularity'])
    else: pass


Lil' Kim 62

In [34]:
lil_kim_popularity = 62

# AGGREGATION PROBLEM
more_popular_than_lil_kim = []

# THE LOOP
for item in items:
    if item['popularity'] > lil_kim_popularity:
        more_popular_than_lil_kim.append(item['name'])
    else:
        pass

for item in more_popular_than_lil_kim:
    print(item)
more_popular_string = ", ".join(more_popular_than_lil_kim)
print(more_popular_string)


Lil Wayne
Lil Yachty
Lil Uzi Vert
Lil Dicky
Boosie Badazz
Lil Jon
Lil Wayne, Lil Yachty, Lil Uzi Vert, Lil Dicky, Boosie Badazz, Lil Jon

5) Pick two of your favorite Lils to fight it out, and use their IDs to print out their top tracks.


In [35]:
#5
# Lil Wayne and Lil June

items = data['artists']['items']
for item in items:
    print (item['name'], item['id'])


Lil Wayne 55Aa2cqylxrFIXC767Z865
Lil Yachty 6icQOAFXDZKsumw3YXyusw
Lil Uzi Vert 4O15NlyKLIASxsJ0PrXPfz
Lil Dicky 1tqhsYv8yBBdwANFNzHtcr
Boosie Badazz 6z7xFFHxYkE9t8bwIF0Bvg
Lil Jon 7sfl4Xt5KmfyDs2T3SVSMK
King Lil G 6L3x3if9RVimruryD9LoFb
Lil Durk 3hcs9uc56yIGFCSy9leWe7
Lil Jon & The East Side Boyz 3ciRvbBIVz9fBoPbtSYq4x
Lil Bibby 4uSN8Y3kgFNVULUWsZEAVW
G Herbo 5QdEbQJ3ylBnc3gsIASAT5
Lil Rob 7B7TGqQe7QTVm2U6q8jzk1
Lil Reese 1bPxKZtCdjB1aj1csBJpdS
Lil Keke 1grI9x4Uzos1Asx8JmRW6T
Bow Wow 7352aRY2mqSxBZwzUb6LmA
Lil Scrappy 5einkgXXrjhfYCyac1FANB
Lil Wyte 21O7WwRkik43ErKppxDKJq
Lil Blood 74nSA5FdDOuuLw7Rn5JnuP
Lil Snupe 42FaEHFfyxTdZQ5W28dXnj
Lil Mama 5qK5bOC6wLtuLhG5KvU17c
Lil B 4dqh62yIzDBmrMeBOLiP5F
Lil' Kim 5tth2a3v0sWwV1C7bApBdX
Lil Cuete 1I5u5Umau1AgHl0ZbPL1oR
Lil Phat 3QnIBUOS4mUzs67rZ8r4c9
Lil Debbie 3FNZcjyqT7F5upP99JV0oN
Lil Twist 564gvOqSRcQoYAhaBpTiK2
Lil Trill 5EQERGi7ffHvHsv3bnqzBn
Lil Twon 5YZZbPdI7P7te3lW3dTpzK
Lil AJ 2jXwYLNnCxNavms4mc1DYM
Lil Lonnie 6zSBkdKFLKKggDtE3amfCk
Lil Boom 1mmlWsyPJvvxMdabcGJjRn
Lil Goofy 3rWaFjgOi5mjQfllMfN3VI
Mr. Lil One 6tslWi0BXiDdtChermDzkU
Lil Haiti 4E9dumwOMLlTyXUp1i2WdI
Lil Flash 069qBEK34YGoX7nSIT74Eg
Lil Kesh 38XiDu0kK3Z5jdHUDqBzNT
Lil Cray 43BqexhEx5NKF7VfeOYP9m
Lil Silva 2Kv0ApBohrL213X9avMrEn
Lil Rue 4IFVaKBbEO8Qkurg6nmoc4
Lil Eddie 5CY0QKsbUBpQJIE2yycsYi
Lil Yase 4vIlHBnzWKbmWe8ZOkT1ZT
Lil Wayne, DJ Drama 65npPa1U4cgobX9wU7Jgpb
Lil Suzy 5HPsVk1MblCoa44WLJsQwN
Lil Mouse 1cEHxCgGlEgqBc91YOcAEQ
Lil C 69swdLSkKxCQBMYJ55O2mA
Lil Rick 1qKzKUnuQsjB83hBZffoq0
Lil June 3GH3KD2078kLPpEkN1UN26
Lil E 0zn6yzsbWj3EPMgOTqfG5k
Lil Fate 6JUnsP7jmvYmdhbg7lTMQj
Lil' Flip 4Q5sPmM8j4SpMqL4UA1DtS

In [38]:
import requests
lil_wayne_id = '55Aa2cqylxrFIXC767Z865'
lil_june_id = '3GH3KD2078kLPpEkN1UN26'

lil_wayne_response = requests.get(https://api.spotify.com/v1/artists/lil_wayne_id/top-tracks?country='US')
lil_wayne_data = lil_wayne_response.json()
lil_june_response = requests.get(https://api.spotify.com/v1/artists/lil_june_id/top-tracks?country='US')
lil_june_data = lil_june_response.json()

lil_wayne_data


  File "<ipython-input-38-ef648cb54837>", line 5
    lil_wayne_response = requests.get(https://api.spotify.com/v1/artists/lil_wayne_id/top-tracks?country='US')
                                           ^
SyntaxError: invalid syntax

In [85]:
# Lil Wayne Top Tracks
wayne_response = requests.get('https://api.spotify.com/v1/artists/55Aa2cqylxrFIXC767Z865/top-tracks')
wayne_data = wayne_response.json()

In [86]:
wayne_data


Out[86]:
dict

In [87]:
wayne_data.keys()


Out[87]:
dict_keys(['error'])

In [ ]: