Graded = 3/8

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 [169]:
import requests

# query = 'lil' type = 'artist' number of responses(limit) = '50' market = 'US'
response = requests.get('https://api.spotify.com/v1/search?q=lil&type=artist&limit=50&market=US')

# data is a string, use json
data = response.json()

# print(type(data))
# print(data.keys())
# print(type(data['artists']))
# print(data['artists'].keys())

artists = data['artists']['items']

# print(type(artists))

for artist in artists: 
    print(artist['name'], artist['popularity'])


Lil Wayne 86
Lil Yachty 74
Lil Uzi Vert 75
Lil Dicky 69
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 Scrappy 50
Bow Wow 57
Lil Keke 48
Lil Wyte 50
Lil Blood 46
Lil Snupe 45
Lil Boom 48
Lil Mama 45
Lil B 43
Lil' Kim 62
Lil Cuete 40
Lil Phat 40
Lil Debbie 43
Lil Twist 40
Lil Trill 37
Lil Goofy 37
Lil Lonnie 37
Lil Haiti 38
Lil AJ 37
Lil Cray 36
Lil Mouse 36
Mr. Lil One 37
Lil Yase 34
Lil Twon 35
Lil Flash 38
Lil Silva 43
Lil Suzy 34
Lil Rue 34
Lil Eddie 41
Lil Kesh 39
Lil Wayne, DJ Drama 35
Lil C 34
Lil Rick 39
Lil E 35
Lil June 32
Lil Fate 34
Lil' Flip 50

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


Lil Wayne 86
Genre list: dirty south rap, pop rap, southern hip hop, trap music
Lil Yachty 74
No genres listed
Lil Uzi Vert 75
No genres listed
Lil Dicky 69
No genres listed
Boosie Badazz 67
No genres listed
Lil Jon 72
Genre list: crunk, dirty south rap, southern hip hop
King Lil G 61
No genres listed
Lil Durk 60
No genres listed
Lil Jon & The East Side Boyz 60
No genres listed
Lil Bibby 54
No genres listed
G Herbo 53
No genres listed
Lil Rob 50
Genre list: chicano rap, latin hip hop
Lil Reese 50
No genres listed
Lil Scrappy 50
Genre list: crunk, dirty south rap, southern hip hop, trap music
Bow Wow 57
Genre list: hip pop, pop rap
Lil Keke 48
No genres listed
Lil Wyte 50
Genre list: juggalo
Lil Blood 46
No genres listed
Lil Snupe 45
No genres listed
Lil Boom 48
No genres listed
Lil Mama 45
Genre list: hip pop
Lil B 43
No genres listed
Lil' Kim 62
Genre list: hip pop
Lil Cuete 40
Genre list: chicano rap
Lil Phat 40
No genres listed
Lil Debbie 43
No genres listed
Lil Twist 40
Genre list: jerk
Lil Trill 37
Genre list: deep trap
Lil Goofy 37
No genres listed
Lil Lonnie 37
No genres listed
Lil Haiti 38
No genres listed
Lil AJ 37
No genres listed
Lil Cray 36
No genres listed
Lil Mouse 36
No genres listed
Mr. Lil One 37
Genre list: chicano rap
Lil Yase 34
No genres listed
Lil Twon 35
No genres listed
Lil Flash 38
No genres listed
Lil Silva 43
No genres listed
Lil Suzy 34
Genre list: freestyle
Lil Rue 34
No genres listed
Lil Eddie 41
No genres listed
Lil Kesh 39
No genres listed
Lil Wayne, DJ Drama 35
No genres listed
Lil C 34
No genres listed
Lil Rick 39
Genre list: soca
Lil E 35
No genres listed
Lil June 32
No genres listed
Lil Fate 34
No genres listed
Lil' Flip 50
Genre list: crunk, dirty south rap

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 [188]:
# sorted in descending order

artists_by_popularity=[(item[0], item[1]) for item in sorted([(item['name'], item['popularity']) for item in artists], key=lambda item: item[1], reverse=True)]

# print second item in list

print(artists_by_popularity[1])

# TA-Stephan: Did not display who has the second highest popularity.


('Lil Uzi Vert', 75)

In [91]:
for artist in artists: 
    if artist['name'] == "Lil' Kim": 
        print (artist['name'], "has a popularity of", artist['popularity'])
        target_score = artist['popularity']

print("So, any artist with a score greater than", target_score, "is more popular than Lil' Kim")

more_popular = [artist['name'] for artist in artists if artist['popularity'] > 62]

print("The following artist have a popularity greater than", target_score, ":")
for artist in more_popular: 
    print(artist)


Lil' Kim has a popularity of 62
So, any artist with a score greater than 62 is more popular than Lil' Kim
The following artist have a popularity greater than 62 :
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. Tip: You're going to be making two separate requests, be sure you DO NOT save them into the same variable.


In [92]:
#TA - Stephan: Want to print out top tracks, not genres

# Find Lil Wayne's id

# for artist in artists: 
#     if artist['name'] == 'Lil Wayne': 
#         print(artist['id'])
        
# get data for top tracks and print list of the artists top tracks
response = requests.get('https://api.spotify.com/v1/artists/55Aa2cqylxrFIXC767Z865/top-tracks?country=US')
data = response.json()
# print(data.keys())
toptracks1 = data['tracks']
print("*****Lil Wayne's top tracks are:*****")
for item in toptracks1: 
    print(item['name'])


# Find Lil Yachty's id 

# for artist in artists: 
#     if artist['name'] == 'Lil Yachty': 
#         print(artist['id'])
    
# get data for top tracks and print list of the artists top tracks
response = requests.get('https://api.spotify.com/v1/artists/6icQOAFXDZKsumw3YXyusw/top-tracks?country=US')
data = response.json()
toptracks2 = data['tracks']
print("*****Lil Yachty's top tracks are:*****")
for item in toptracks2: 
    print(item['name'])


*****Lil Wayne's top tracks are:*****
Forever
Nothing But Trouble - Instagram Models
6 Foot 7 Foot
A Milli
Right Above It
Lollipop
Rich As Fuck
Love Me
Mirror
Believe Me
*****Lil Yachty's top tracks are:*****
One Night (Extended)
Minnesota (Remix) [feat. Quavo, Skippa da Flippa & Young Thug]
Wanna Be Us (feat. Burberry Perry)
Intro (Just Keep Swimming)
Up Next 2 (feat. Big Brutha Chubba & Byou)
Good Day (feat. Skippa da Flippa)
Not My Bro
Fucked Over
Out Late
Interlude

6) Will the world explode if a musicians swears? Get an average popularity for their explicit songs vs. their non-explicit songs. How many minutes of explicit songs do they have? Non-explicit?


In [119]:
#changed to Lil Jon because Lil Wayne and Lil Yachty have 100 percent explicit songs

# for artist in artists: 
#     if artist['name'] == 'Lil Jon': 
#         print(artist['id'])

# request data for Lil Jon top tracks
response = requests.get('https://api.spotify.com/v1/artists/7sfl4Xt5KmfyDs2T3SVSMK/top-tracks?country=US')
data = response.json()
toptracks3 = data['tracks']

#check dict keys 
# print(toptracks3[0].keys())

# explicit songs 
explicit_pops = [item['popularity']for item in toptracks3 if item['explicit']]
avg_explicit_pop = sum(explicit_pops)/len(explicit_pops)
print("The average popularity for Lil Jon's explicit songs are", avg_explicit_pop)

explicit_ms = [item['duration_ms'] for item in toptracks3 if item['explicit']]
tot_explicit_min = sum(explicit_ms)/60000
print("He has", tot_explicit_min, "minutes of explicit songs")

# non-explicit songs
nonexplicit_pops = [item['popularity']for item in toptracks3 if not item['explicit']]
avg_nonexplicit_pop = sum(nonexplicit_pops)/len(nonexplicit_pops)
print("The average popularity for Lil Jon's non-explicit songs are", avg_nonexplicit_pop)

nonexplicit_ms = [item['duration_ms'] for item in toptracks3 if not item['explicit']]
tot_nonexplicit_min = sum(nonexplicit_ms)/60000
print("He has", tot_nonexplicit_min, "minutes of non-explicit songs")


The average popularity for Lil Jon's explicit songs are 54.857142857142854
He has 24.620966666666668 minutes of explicit songs
The average popularity for Lil Jon's non-explicit songs are 70.66666666666667
He has 12.847083333333334 minutes of non-explicit songs

7) Since we're talking about Lils, what about Biggies? How many total "Biggie" artists are there? How many total "Lil"s? If you made 1 request every 5 seconds, how long would it take to download information on all the Lils vs the Biggies?


In [168]:
response = requests.get("https://api.spotify.com/v1/search?q=biggie*&type=artist&limit=50")
data = response.json()
print(data)
artists = data['artists']['items']
artist_name=[item['name'] for item in artists]
print(len(artist_name))


{'artists': {'total': 50, 'next': 'https://api.spotify.com/v1/search?query=biggie*&offset=30&limit=20&type=artist', 'href': 'https://api.spotify.com/v1/search?query=biggie*&offset=10&limit=20&type=artist', 'limit': 20, 'previous': 'https://api.spotify.com/v1/search?query=biggie*&offset=0&limit=20&type=artist', 'offset': 10, 'items': [{'type': 'artist', 'uri': 'spotify:artist:0wzeEbcsUKiP1mZLkeC3iB', 'popularity': 0, 'external_urls': {'spotify': 'https://open.spotify.com/artist/0wzeEbcsUKiP1mZLkeC3iB'}, 'followers': {'total': 9, 'href': None}, 'name': 'Mister Biggie', 'id': '0wzeEbcsUKiP1mZLkeC3iB', 'genres': [], 'href': 'https://api.spotify.com/v1/artists/0wzeEbcsUKiP1mZLkeC3iB', 'images': []}, {'type': 'artist', 'uri': 'spotify:artist:0ylErua0QWjJm1xExk8NCa', 'popularity': 0, 'external_urls': {'spotify': 'https://open.spotify.com/artist/0ylErua0QWjJm1xExk8NCa'}, 'followers': {'total': 2, 'href': None}, 'name': 'Biggie & Foldy', 'id': '0ylErua0QWjJm1xExk8NCa', 'genres': [], 'href': 'https://api.spotify.com/v1/artists/0ylErua0QWjJm1xExk8NCa', 'images': [{'url': 'https://i.scdn.co/image/4032748fe023f8340827f3e5536fe727660384d0', 'height': 640, 'width': 640}, {'url': 'https://i.scdn.co/image/7d0abfb01458e34f233fdc1eab0903de562ef915', 'height': 300, 'width': 300}, {'url': 'https://i.scdn.co/image/355b60f390db34a3b48b11c349d2bd7b7e9247c1', 'height': 64, 'width': 64}]}, {'type': 'artist', 'uri': 'spotify:artist:52bcshIAYPMvoEnEmwus6N', 'popularity': 6, 'external_urls': {'spotify': 'https://open.spotify.com/artist/52bcshIAYPMvoEnEmwus6N'}, 'followers': {'total': 21, 'href': None}, 'name': 'Biggie Bash', 'id': '52bcshIAYPMvoEnEmwus6N', 'genres': [], 'href': 'https://api.spotify.com/v1/artists/52bcshIAYPMvoEnEmwus6N', 'images': []}, {'type': 'artist', 'uri': 'spotify:artist:2FU57JKnCnLVaSXaCiTaY8', 'popularity': 2, 'external_urls': {'spotify': 'https://open.spotify.com/artist/2FU57JKnCnLVaSXaCiTaY8'}, 'followers': {'total': 15, 'href': None}, 'name': 'Dj Majah & Blaq Biggie Blaq', 'id': '2FU57JKnCnLVaSXaCiTaY8', 'genres': [], 'href': 'https://api.spotify.com/v1/artists/2FU57JKnCnLVaSXaCiTaY8', 'images': []}, {'type': 'artist', 'uri': 'spotify:artist:3WbEnNpaSNPnYzHRXj73WS', 'popularity': 1, 'external_urls': {'spotify': 'https://open.spotify.com/artist/3WbEnNpaSNPnYzHRXj73WS'}, 'followers': {'total': 12, 'href': None}, 'name': 'Biggie Tembo', 'id': '3WbEnNpaSNPnYzHRXj73WS', 'genres': ['zim'], 'href': 'https://api.spotify.com/v1/artists/3WbEnNpaSNPnYzHRXj73WS', 'images': []}, {'type': 'artist', 'uri': 'spotify:artist:10WpL7wK50c2RMbaSjPAT5', 'popularity': 0, 'external_urls': {'spotify': 'https://open.spotify.com/artist/10WpL7wK50c2RMbaSjPAT5'}, 'followers': {'total': 1, 'href': None}, 'name': 'Louis Biggie', 'id': '10WpL7wK50c2RMbaSjPAT5', 'genres': [], 'href': 'https://api.spotify.com/v1/artists/10WpL7wK50c2RMbaSjPAT5', 'images': [{'url': 'https://i.scdn.co/image/a7830166f311fa73165d7f823dd1043e6d85db4d', 'height': 640, 'width': 640}, {'url': 'https://i.scdn.co/image/19a4a546d23697789736fe8f0940771432b965c7', 'height': 300, 'width': 300}, {'url': 'https://i.scdn.co/image/e79fe8573379b7d7f2eca351cd881830b1af665f', 'height': 64, 'width': 64}]}, {'type': 'artist', 'uri': 'spotify:artist:4KtKqs3wbli7oTsLjpuRKq', 'popularity': 0, 'external_urls': {'spotify': 'https://open.spotify.com/artist/4KtKqs3wbli7oTsLjpuRKq'}, 'followers': {'total': 0, 'href': None}, 'name': 'Biggie Da Roxter', 'id': '4KtKqs3wbli7oTsLjpuRKq', 'genres': [], 'href': 'https://api.spotify.com/v1/artists/4KtKqs3wbli7oTsLjpuRKq', 'images': []}, {'type': 'artist', 'uri': 'spotify:artist:0cExlEbrUiYO6Wq1VDyC0D', 'popularity': 0, 'external_urls': {'spotify': 'https://open.spotify.com/artist/0cExlEbrUiYO6Wq1VDyC0D'}, 'followers': {'total': 6, 'href': None}, 'name': 'Biggie Dutch', 'id': '0cExlEbrUiYO6Wq1VDyC0D', 'genres': [], 'href': 'https://api.spotify.com/v1/artists/0cExlEbrUiYO6Wq1VDyC0D', 'images': [{'url': 'https://i.scdn.co/image/25552a15238824e72d45c7d8e98a695938f42410', 'height': 600, 'width': 600}, {'url': 'https://i.scdn.co/image/52ea1edfecea9695b7a78ead7a060587d363fc48', 'height': 300, 'width': 300}, {'url': 'https://i.scdn.co/image/f0bc3e9276e40c8648f4c2f486567e2c5d93a810', 'height': 64, 'width': 64}]}, {'type': 'artist', 'uri': 'spotify:artist:1BGFuzglzV871bnwTMVLzR', 'popularity': 0, 'external_urls': {'spotify': 'https://open.spotify.com/artist/1BGFuzglzV871bnwTMVLzR'}, 'followers': {'total': 0, 'href': None}, 'name': 'Biggie Dutch feat. Marina Wilde', 'id': '1BGFuzglzV871bnwTMVLzR', 'genres': [], 'href': 'https://api.spotify.com/v1/artists/1BGFuzglzV871bnwTMVLzR', 'images': [{'url': 'https://i.scdn.co/image/87e8136e9371dd78f0e289c358136786aa3c6059', 'height': 600, 'width': 600}, {'url': 'https://i.scdn.co/image/5b3a6db14f1b7f5fc2381d2a84c23ca91813caa7', 'height': 300, 'width': 300}, {'url': 'https://i.scdn.co/image/ccae34918f20d9f63d36c8c6608d426fb033e797', 'height': 64, 'width': 64}]}, {'type': 'artist', 'uri': 'spotify:artist:0cbg8Q3ul7S0EOg53foHP1', 'popularity': 0, 'external_urls': {'spotify': 'https://open.spotify.com/artist/0cbg8Q3ul7S0EOg53foHP1'}, 'followers': {'total': 0, 'href': None}, 'name': 'MC Biggie', 'id': '0cbg8Q3ul7S0EOg53foHP1', 'genres': [], 'href': 'https://api.spotify.com/v1/artists/0cbg8Q3ul7S0EOg53foHP1', 'images': []}, {'type': 'artist', 'uri': 'spotify:artist:7s6FI4ZY7aYqZJTMFZVh5z', 'popularity': 0, 'external_urls': {'spotify': 'https://open.spotify.com/artist/7s6FI4ZY7aYqZJTMFZVh5z'}, 'followers': {'total': 1, 'href': None}, 'name': 'Mr Biggie', 'id': '7s6FI4ZY7aYqZJTMFZVh5z', 'genres': [], 'href': 'https://api.spotify.com/v1/artists/7s6FI4ZY7aYqZJTMFZVh5z', 'images': []}, {'type': 'artist', 'uri': 'spotify:artist:5sOKmPQsWh90sEqdJVj9uA', 'popularity': 0, 'external_urls': {'spotify': 'https://open.spotify.com/artist/5sOKmPQsWh90sEqdJVj9uA'}, 'followers': {'total': 0, 'href': None}, 'name': 'Biggie & Anjay', 'id': '5sOKmPQsWh90sEqdJVj9uA', 'genres': [], 'href': 'https://api.spotify.com/v1/artists/5sOKmPQsWh90sEqdJVj9uA', 'images': []}, {'type': 'artist', 'uri': 'spotify:artist:01ETg7HperPOO5SIFjSMns', 'popularity': 2, 'external_urls': {'spotify': 'https://open.spotify.com/artist/01ETg7HperPOO5SIFjSMns'}, 'followers': {'total': 8, 'href': None}, 'name': 'Balder & Biggie', 'id': '01ETg7HperPOO5SIFjSMns', 'genres': [], 'href': 'https://api.spotify.com/v1/artists/01ETg7HperPOO5SIFjSMns', 'images': [{'url': 'https://i.scdn.co/image/98c54d150b5cfb3b28a30063100bcdc5111503ea', 'height': 640, 'width': 640}, {'url': 'https://i.scdn.co/image/08ad6f980407747e448115f1ab139b26fc95e1ae', 'height': 300, 'width': 300}, {'url': 'https://i.scdn.co/image/5d24c33c9f0d70883017c2062e86fa3a730c3dbf', 'height': 64, 'width': 64}]}, {'type': 'artist', 'uri': 'spotify:artist:6XgdbcdYU6UX6VXb58CuSq', 'popularity': 0, 'external_urls': {'spotify': 'https://open.spotify.com/artist/6XgdbcdYU6UX6VXb58CuSq'}, 'followers': {'total': 5, 'href': None}, 'name': 'Poppa Biggie', 'id': '6XgdbcdYU6UX6VXb58CuSq', 'genres': [], 'href': 'https://api.spotify.com/v1/artists/6XgdbcdYU6UX6VXb58CuSq', 'images': [{'url': 'https://i.scdn.co/image/b928544e91e2168c99d8bfe0fa6523b1a46678fd', 'height': 640, 'width': 640}, {'url': 'https://i.scdn.co/image/47839f58562030a11d06ee5f973c48b95a22de2b', 'height': 300, 'width': 300}, {'url': 'https://i.scdn.co/image/26eff86e3e88431d2a51d41f6ff8d70790f91849', 'height': 64, 'width': 64}]}, {'type': 'artist', 'uri': 'spotify:artist:0d6ZzL7oqz1yvwLPBnYthO', 'popularity': 0, 'external_urls': {'spotify': 'https://open.spotify.com/artist/0d6ZzL7oqz1yvwLPBnYthO'}, 'followers': {'total': 0, 'href': None}, 'name': 'Biggie Mic', 'id': '0d6ZzL7oqz1yvwLPBnYthO', 'genres': [], 'href': 'https://api.spotify.com/v1/artists/0d6ZzL7oqz1yvwLPBnYthO', 'images': []}, {'type': 'artist', 'uri': 'spotify:artist:1rzXoaOU1vD7hbsRJpMhIQ', 'popularity': 0, 'external_urls': {'spotify': 'https://open.spotify.com/artist/1rzXoaOU1vD7hbsRJpMhIQ'}, 'followers': {'total': 0, 'href': None}, 'name': 'Babie Biggie', 'id': '1rzXoaOU1vD7hbsRJpMhIQ', 'genres': [], 'href': 'https://api.spotify.com/v1/artists/1rzXoaOU1vD7hbsRJpMhIQ', 'images': []}, {'type': 'artist', 'uri': 'spotify:artist:1F5YvPFuHD09sUf61xhMPp', 'popularity': 0, 'external_urls': {'spotify': 'https://open.spotify.com/artist/1F5YvPFuHD09sUf61xhMPp'}, 'followers': {'total': 0, 'href': None}, 'name': 'Biggie Moe', 'id': '1F5YvPFuHD09sUf61xhMPp', 'genres': [], 'href': 'https://api.spotify.com/v1/artists/1F5YvPFuHD09sUf61xhMPp', 'images': []}, {'type': 'artist', 'uri': 'spotify:artist:1TZAZqjCNXzW5bd9ZZFRfr', 'popularity': 0, 'external_urls': {'spotify': 'https://open.spotify.com/artist/1TZAZqjCNXzW5bd9ZZFRfr'}, 'followers': {'total': 0, 'href': None}, 'name': 'MC Biggiedoy', 'id': '1TZAZqjCNXzW5bd9ZZFRfr', 'genres': [], 'href': 'https://api.spotify.com/v1/artists/1TZAZqjCNXzW5bd9ZZFRfr', 'images': []}, {'type': 'artist', 'uri': 'spotify:artist:46Qf7VZQKEDy14dJF70j7N', 'popularity': 0, 'external_urls': {'spotify': 'https://open.spotify.com/artist/46Qf7VZQKEDy14dJF70j7N'}, 'followers': {'total': 0, 'href': None}, 'name': 'Biggie Lu', 'id': '46Qf7VZQKEDy14dJF70j7N', 'genres': [], 'href': 'https://api.spotify.com/v1/artists/46Qf7VZQKEDy14dJF70j7N', 'images': [{'url': 'https://i.scdn.co/image/33bc566e51dc8e10699fb7f5dd62c922d867317e', 'height': 640, 'width': 640}, {'url': 'https://i.scdn.co/image/ab5f1fb81a6f912109e02774b6ce17566995b6ca', 'height': 300, 'width': 300}, {'url': 'https://i.scdn.co/image/b07c2ac0fea586e2577f60895eb93abd296078cf', 'height': 64, 'width': 64}]}, {'type': 'artist', 'uri': 'spotify:artist:0Rn34aKuTIzRiXrkh7o9or', 'popularity': 0, 'external_urls': {'spotify': 'https://open.spotify.com/artist/0Rn34aKuTIzRiXrkh7o9or'}, 'followers': {'total': 3, 'href': None}, 'name': 'Biggie Bandit', 'id': '0Rn34aKuTIzRiXrkh7o9or', 'genres': [], 'href': 'https://api.spotify.com/v1/artists/0Rn34aKuTIzRiXrkh7o9or', 'images': [{'url': 'https://i.scdn.co/image/b6100be209469688c1a96f9ef3ad8d240ffe67fc', 'height': 640, 'width': 640}, {'url': 'https://i.scdn.co/image/8a4333f6c50ecbb5c467d31a5ef7b125415f1ad2', 'height': 300, 'width': 300}, {'url': 'https://i.scdn.co/image/db7ee2a8fe5b00116a8504d610df7c9f9c77ca4e', 'height': 64, 'width': 64}]}]}}
20

8) Out of the top 50 "Lil"s and the top 50 "Biggie"s, who is more popular on average?


In [ ]: