In [2]:
import requests

1) With "Lil Wayne" and "Lil Kim" there are a lot of "Lil" musicians. Do a search and print a list of 50 that are playable in the USA (or the country of your choice), along with their popularity score.


In [3]:
response = requests.get('https://api.spotify.com/v1/search?q=lil&type=artist&?country=US&limit=50')
data = response.json()

In [4]:
type(data)


Out[4]:
dict

In [5]:
data.keys()


Out[5]:
dict_keys(['artists'])

In [6]:
data['artists'].keys()


Out[6]:
dict_keys(['offset', 'next', 'href', 'items', 'total', 'limit', 'previous'])

In [7]:
artists = data['artists']['items']

In [8]:
for artist in artists:
    print(artist['name'], artist['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 [11]:
for artist in artists:
    print (artist['name'], artist['popularity'])
    if len(artist['genres']) != 0:
        print(", ".join(artist['genres'])
    else:
        print ("No genres listed")


  File "<ipython-input-11-0354c5543f32>", line 5
    else:
       ^
SyntaxError: invalid syntax

In [51]:
# AGGREGATION PROBLEM
all_genres = []
# THE LOOP
for artist in artists:
    print ("ALL GENRES WE'VE HEARD OF:", all_genres)
    # THE CONDITIONAL: none
    print("Current artist has:", artist['genres'])
    all_genres = all_genres + artist['genres']
print ("ALLL THE GENRES WE'VE HEARD OF, FINALLY, AT THE END:")
# Has repeats
print (all_genres)

# your_list = ['a', 'b', 'c', 'c', 'c']
# your_list.count('a') = 1
# your_list.count('c') = 3


ALL GENRES WE'VE HEARD OF: []
Current artist has: ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music']
ALL GENRES WE'VE HEARD OF: ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music']
Current artist has: []
ALL GENRES WE'VE HEARD OF: ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music']
Current artist has: []
ALL GENRES WE'VE HEARD OF: ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music']
Current artist has: []
ALL GENRES WE'VE HEARD OF: ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music']
Current artist has: []
ALL GENRES WE'VE HEARD OF: ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music']
Current artist has: ['crunk', 'dirty south rap', 'southern hip hop']
ALL GENRES WE'VE HEARD OF: ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop']
Current artist has: []
ALL GENRES WE'VE HEARD OF: ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop']
Current artist has: []
ALL GENRES WE'VE HEARD OF: ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop']
Current artist has: []
ALL GENRES WE'VE HEARD OF: ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop']
Current artist has: []
ALL GENRES WE'VE HEARD OF: ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop']
Current artist has: []
ALL GENRES WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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 WE'VE HEARD OF: ['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']
ALLL THE GENRES WE'VE HEARD OF, FINALLY, AT THE END:
['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 [52]:
# This is bad becuase of the duplicates

for genre in all_genres:
    genre_count = all_genres.count(genre)
    print(genre, "shows up", genre_count, "times")


dirty south rap shows up 4 times
pop rap shows up 2 times
southern hip hop shows up 3 times
trap music shows up 2 times
crunk shows up 3 times
dirty south rap shows up 4 times
southern hip hop shows up 3 times
chicano rap shows up 3 times
latin hip hop shows up 1 times
hip pop shows up 3 times
pop rap shows up 2 times
crunk shows up 3 times
dirty south rap shows up 4 times
southern hip hop shows up 3 times
trap music shows up 2 times
juggalo shows up 1 times
hip pop shows up 3 times
hip pop shows up 3 times
chicano rap shows up 3 times
jerk shows up 1 times
deep trap shows up 1 times
chicano rap shows up 3 times
freestyle shows up 1 times
soca shows up 1 times
crunk shows up 3 times
dirty south rap shows up 4 times

In [54]:
# We need a UNIQUE list of all_genres, a.k.a. a list
# with all duplicates removed
# unique_list = set(list_with_duplicates)
unique_genres = set(all_genres)
for genre in unique_genres:
    genre_count = all_genres.count(genre)
    print(genre, "shows up", genre_count, "times")


hip pop shows up 3 times
trap music shows up 2 times
juggalo shows up 1 times
soca shows up 1 times
crunk shows up 3 times
dirty south rap shows up 4 times
latin hip hop shows up 1 times
deep trap shows up 1 times
pop rap shows up 2 times
chicano rap shows up 3 times
jerk shows up 1 times
southern hip hop shows up 3 times
freestyle shows up 1 times

In [59]:
# There is a library that comes with Python called COLLECTIONS!
# Inside of it is a magic thing alled Counter

# import collections
from collections import Counter
# all_genres = ['sourthern hip hop', 'souther hip hop', 'crunk', ]
counts = Counter(all_genres) #looks like dictionary # import collection -> collection.Counter
counts['crunk'] #so we can do this
counts.most_common(4)


Out[59]:
[('dirty south rap', 4), ('hip pop', 3), ('crunk', 3), ('southern hip hop', 3)]

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 [32]:
most_popular_name = ""
most_popular_score = 0
for artist in artists:
    print ("Looking at", artist['name'], "who has popularity score of", artist['popularity'])
    # THE CONDITIONAL
    # a.k.a. what you are testing
    print ("Comparing", artist['popularity'], "to", most_popular_score)
    if artist['popularity'] > most_popular_score:
        print ("FOUND NEW MOST POPULAR, checking to see if it's Lil Wayne")
        # Seeing if it's actually Lil Wayne
        if artist['name'] == "Lil Wayne":
            print ("Nice try Lil Wayne, we don't care")
        # THE CHANGE
        # a.k.a. what you're keeping track of
        else:
            print ("NEW POPULAR! Updating our notebook")
            most_popular_name = artist['name']
            most_popular_score = artist['popularity']
print ("+++++++++++++++++++++++")
print(most_popular_name, most_popular_score)


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

In [41]:
target_score = 72
# 1: INITIAL CONDITION
# We have no one who is in our list yet
second_best_artists = []

# AGGREGATION PROBLEM
# When you're looking through a series of serious objects
# and sometimes you want to add one of those objects
# to a DIFFERENT list
for artist in artists:
    print ("Looking at", artist['name'], "who has a popularity of", artist['popularity'])
    # 2: CONDITIONAL
    # When we want to add someone to our list
    if artist['popularity'] == 72:
        print ("!!!!!! The artist's popularity is 72")
        # 3: THE CHANGE
        # Add that artist to our list
        # .append(newthing) is how we do that in Python
        second_best_artists.append(artist['name'])
print ("OUR SECOND BEST ARTISTS ARE:")
for artist in second_best_artists:
    print(artist['name'])


Looking at Lil Wayne who has a popularity of 86
Looking at Lil Yachty who has a popularity of 72
!!!!!! The artist's popularity is 72
Looking at Lil Uzi Vert who has a popularity of 72
!!!!!! The artist's popularity is 72
Looking at Lil Dicky who has a popularity of 68
Looking at Boosie Badazz who has a popularity of 67
Looking at Lil Jon who has a popularity of 72
!!!!!! The artist's popularity is 72
Looking at King Lil G who has a popularity of 61
Looking at Lil Durk who has a popularity of 60
Looking at Lil Jon & The East Side Boyz who has a popularity of 60
Looking at Lil Bibby who has a popularity of 54
Looking at G Herbo who has a popularity of 53
Looking at Lil Rob who has a popularity of 50
Looking at Lil Reese who has a popularity of 50
Looking at Lil Keke who has a popularity of 48
Looking at Bow Wow who has a popularity of 57
Looking at Lil Scrappy who has a popularity of 48
Looking at Lil Wyte who has a popularity of 50
Looking at Lil Blood who has a popularity of 45
Looking at Lil Snupe who has a popularity of 45
Looking at Lil Mama who has a popularity of 45
Looking at Lil B who has a popularity of 44
Looking at Lil' Kim who has a popularity of 62
Looking at Lil Cuete who has a popularity of 40
Looking at Lil Phat who has a popularity of 39
Looking at Lil Debbie who has a popularity of 43
Looking at Lil Twist who has a popularity of 39
Looking at Lil Trill who has a popularity of 37
Looking at Lil Twon who has a popularity of 38
Looking at Lil AJ who has a popularity of 37
Looking at Lil Lonnie who has a popularity of 37
Looking at Lil Boom who has a popularity of 35
Looking at Lil Goofy who has a popularity of 35
Looking at Mr. Lil One who has a popularity of 36
Looking at Lil Haiti who has a popularity of 36
Looking at Lil Flash who has a popularity of 38
Looking at Lil Kesh who has a popularity of 39
Looking at Lil Cray who has a popularity of 35
Looking at Lil Silva who has a popularity of 43
Looking at Lil Rue who has a popularity of 34
Looking at Lil Eddie who has a popularity of 41
Looking at Lil Yase who has a popularity of 33
Looking at Lil Wayne, DJ Drama who has a popularity of 35
Looking at Lil Suzy who has a popularity of 34
Looking at Lil Mouse who has a popularity of 34
Looking at Lil C who has a popularity of 33
Looking at Lil Rick who has a popularity of 39
Looking at Lil June who has a popularity of 32
Looking at Lil E who has a popularity of 34
Looking at Lil Fate who has a popularity of 34
Looking at Lil' Flip who has a popularity of 49
OUR SECOND BEST ARTISTS ARE:
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-41-0690d2398079> in <module>()
     20 print ("OUR SECOND BEST ARTISTS ARE:")
     21 for artist in second_best_artists:
---> 22     print(artist['name'])

TypeError: string indices must be integers

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


In [43]:
for artist in artists:
    # print ("Looking at", artist['name'])
    print
    if artist['name'] == "Lil' Kim":
        print ('Found Lil Kim')
        print(artist['popularity'])
    else:
        pass
        # print("Not Lil Kim")


Looking at Lil Wayne
Looking at Lil Yachty
Looking at Lil Uzi Vert
Looking at Lil Dicky
Looking at Boosie Badazz
Looking at Lil Jon
Looking at King Lil G
Looking at Lil Durk
Looking at Lil Jon & The East Side Boyz
Looking at Lil Bibby
Looking at G Herbo
Looking at Lil Rob
Looking at Lil Reese
Looking at Lil Keke
Looking at Bow Wow
Looking at Lil Scrappy
Looking at Lil Wyte
Looking at Lil Blood
Looking at Lil Snupe
Looking at Lil Mama
Looking at Lil B
Looking at Lil' Kim
Found Lil Kim
62
Looking at Lil Cuete
Looking at Lil Phat
Looking at Lil Debbie
Looking at Lil Twist
Looking at Lil Trill
Looking at Lil Twon
Looking at Lil AJ
Looking at Lil Lonnie
Looking at Lil Boom
Looking at Lil Goofy
Looking at Mr. Lil One
Looking at Lil Haiti
Looking at Lil Flash
Looking at Lil Kesh
Looking at Lil Cray
Looking at Lil Silva
Looking at Lil Rue
Looking at Lil Eddie
Looking at Lil Yase
Looking at Lil Wayne, DJ Drama
Looking at Lil Suzy
Looking at Lil Mouse
Looking at Lil C
Looking at Lil Rick
Looking at Lil June
Looking at Lil E
Looking at Lil Fate
Looking at Lil' Flip

In [45]:
lil_kim_popularity = 62
# AGGREGATION PROBLEM
more_popular_than_lil_kim = []

# THE LOOP
for artist in artists:
    # THE CONDITIONAL is the artist more popular than lil kim?
    if artist['popularity'] > lil_kim_popularity:
        # IF yes, let's add them to our list
        print (artist['name'], "is MORE POPULAR with a socre of", artist['popularity'])
        more_popular_than_lil_kim.append(artist['name'])
    else:
        print(artist['name'], "is less popular with a socre of", artist['popularity'])
print ("++++++++++++++ MORE POPULAR THAN LIL KIM")


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

In [47]:
for artist_name in more_popular_than_lil_kim:
    print (artist_name)

more_popular_string = ", ".join(more_popular_than_lil_kim)
print ("Artists more popular than Lil' Kim are:", more_popular_string)


Lil Wayne
Lil Yachty
Lil Uzi Vert
Lil Dicky
Boosie Badazz
Lil Jon
Artists more popular than Lil' Kim are: Lil Wayne, Lil Yachty, Lil Uzi Vert, Lil Dicky, Boosie Badazz, Lil Jon

How to automate getting all of the results


In [73]:
response = requests.get('https://api.spotify.com/v1/search?q=lil&type=artist&?country=US&limit=50')
small_data = response.json()

In [74]:
small_data['artists']
print (len(small_data['artists']['items'])) # we only get 10 artists
print(data['artists']['total'])


50
4502

In [80]:
import math
#response = requests.get('https://api.spotify.com/v1/search?q=lil&type=artist&limit=50')
#small_data = response.json()
page_count = math.ceil(4502/50)
page_count


Out[80]:
91

In [ ]:
list(range(0,91))

In [82]:
# First Page: artists 1-50
# 'https://api.spotify.com/v1/search?q=lil&type=artist&limit=50'
# Second Page:  artists 51-100, offset of 50
# 'https://api.spotify.com/v1/search?q=lil&type=artist&limit=50&offset=50'
# Third Page: artists 101-150
# 'https://api.spotify.com/v1/search?q=lil&type=artist&limit=50&offset=100'
# Forth Page: artists 151-200
# 'https://api.spotify.com/v1/search?q=lil&type=artist&limit=50&offset=150'
all_artists = []
for page in range(91):
    offset = (page*50)
    print ("we are on page", page+1, "with an offset of", offset)
    # make the request with a changed offset ?offset={offset}
    # data  = response.json()
    # add our new artists to our list of existing artists
    # all_artists = all_artists + data['artists']['items']
print ("successfully retrived", len(all_artists), "artists")


we are on page 1 with an offset of 0
we are on page 2 with an offset of 50
we are on page 3 with an offset of 100
we are on page 4 with an offset of 150
we are on page 5 with an offset of 200
we are on page 6 with an offset of 250
we are on page 7 with an offset of 300
we are on page 8 with an offset of 350
we are on page 9 with an offset of 400
we are on page 10 with an offset of 450
we are on page 11 with an offset of 500
we are on page 12 with an offset of 550
we are on page 13 with an offset of 600
we are on page 14 with an offset of 650
we are on page 15 with an offset of 700
we are on page 16 with an offset of 750
we are on page 17 with an offset of 800
we are on page 18 with an offset of 850
we are on page 19 with an offset of 900
we are on page 20 with an offset of 950
we are on page 21 with an offset of 1000
we are on page 22 with an offset of 1050
we are on page 23 with an offset of 1100
we are on page 24 with an offset of 1150
we are on page 25 with an offset of 1200
we are on page 26 with an offset of 1250
we are on page 27 with an offset of 1300
we are on page 28 with an offset of 1350
we are on page 29 with an offset of 1400
we are on page 30 with an offset of 1450
we are on page 31 with an offset of 1500
we are on page 32 with an offset of 1550
we are on page 33 with an offset of 1600
we are on page 34 with an offset of 1650
we are on page 35 with an offset of 1700
we are on page 36 with an offset of 1750
we are on page 37 with an offset of 1800
we are on page 38 with an offset of 1850
we are on page 39 with an offset of 1900
we are on page 40 with an offset of 1950
we are on page 41 with an offset of 2000
we are on page 42 with an offset of 2050
we are on page 43 with an offset of 2100
we are on page 44 with an offset of 2150
we are on page 45 with an offset of 2200
we are on page 46 with an offset of 2250
we are on page 47 with an offset of 2300
we are on page 48 with an offset of 2350
we are on page 49 with an offset of 2400
we are on page 50 with an offset of 2450
we are on page 51 with an offset of 2500
we are on page 52 with an offset of 2550
we are on page 53 with an offset of 2600
we are on page 54 with an offset of 2650
we are on page 55 with an offset of 2700
we are on page 56 with an offset of 2750
we are on page 57 with an offset of 2800
we are on page 58 with an offset of 2850
we are on page 59 with an offset of 2900
we are on page 60 with an offset of 2950
we are on page 61 with an offset of 3000
we are on page 62 with an offset of 3050
we are on page 63 with an offset of 3100
we are on page 64 with an offset of 3150
we are on page 65 with an offset of 3200
we are on page 66 with an offset of 3250
we are on page 67 with an offset of 3300
we are on page 68 with an offset of 3350
we are on page 69 with an offset of 3400
we are on page 70 with an offset of 3450
we are on page 71 with an offset of 3500
we are on page 72 with an offset of 3550
we are on page 73 with an offset of 3600
we are on page 74 with an offset of 3650
we are on page 75 with an offset of 3700
we are on page 76 with an offset of 3750
we are on page 77 with an offset of 3800
we are on page 78 with an offset of 3850
we are on page 79 with an offset of 3900
we are on page 80 with an offset of 3950
we are on page 81 with an offset of 4000
we are on page 82 with an offset of 4050
we are on page 83 with an offset of 4100
we are on page 84 with an offset of 4150
we are on page 85 with an offset of 4200
we are on page 86 with an offset of 4250
we are on page 87 with an offset of 4300
we are on page 88 with an offset of 4350
we are on page 89 with an offset of 4400
we are on page 90 with an offset of 4450
we are on page 91 with an offset of 4500
successfully retrived 0 artists

In [ ]:
response = request.get('')