Grade: 8 / 8


In [1]:
import requests

In [2]:
lil_response = requests.get('https://api.spotify.com/v1/search?q=Lil&type=artist&market=US&limit=50')
raw_lil_data=lil_response.json()
artists=raw_lil_data['artists']['items']

In [3]:
print('Here are 50 Lil-adjacent artists for you to peruse:')
artist_count=0
for artist in artists:
    artist_count=artist_count+1
    print(artist_count, artist['name'], artist['popularity'])


Here are 50 Lil-adjacent artists for you to peruse:
1 Lil Wayne 86
2 Lil Yachty 72
3 Lil Uzi Vert 72
4 Lil Dicky 68
5 Boosie Badazz 67
6 Lil Jon 72
7 King Lil G 61
8 Lil Durk 60
9 Lil Jon & The East Side Boyz 60
10 Lil Bibby 54
11 G Herbo 53
12 Lil Rob 50
13 Lil Reese 50
14 Lil Keke 48
15 Bow Wow 57
16 Lil Scrappy 49
17 Lil Wyte 50
18 Lil Blood 45
19 Lil Snupe 45
20 Lil Mama 45
21 Lil B 44
22 Lil' Kim 62
23 Lil Cuete 40
24 Lil Phat 39
25 Lil Debbie 43
26 Lil Twist 39
27 Lil Trill 37
28 Lil Twon 38
29 Lil AJ 37
30 Lil Lonnie 36
31 Lil Goofy 35
32 Mr. Lil One 36
33 Lil Haiti 36
34 Lil Flash 38
35 Lil Kesh 39
36 Lil Cray 35
37 Lil Rue 34
38 Lil Silva 43
39 Lil Eddie 41
40 Lil Boom 34
41 Lil Yase 33
42 Lil Wayne, DJ Drama 35
43 Lil Suzy 34
44 Lil Mouse 34
45 Lil C 33
46 Lil Rick 39
47 Lil E 34
48 Lil June 32
49 Lil Fate 34
50 Lil' Flip 49

In [4]:
print('Here is that same list but with genres, maybe:')
for artist in artists:
    if not artist['genres']:
        print(artist['name'], 'stinks and has no genres')
    else:
        print(artist['name'], 'is', ", ".join(artist['genres']))


Here is that same list but with genres, maybe:
Lil Wayne is dirty south rap, pop rap, southern hip hop, trap music
Lil Yachty stinks and has no genres
Lil Uzi Vert stinks and has no genres
Lil Dicky stinks and has no genres
Boosie Badazz stinks and has no genres
Lil Jon is crunk, dirty south rap, southern hip hop
King Lil G stinks and has no genres
Lil Durk stinks and has no genres
Lil Jon & The East Side Boyz stinks and has no genres
Lil Bibby stinks and has no genres
G Herbo stinks and has no genres
Lil Rob is chicano rap, latin hip hop
Lil Reese stinks and has no genres
Lil Keke stinks and has no genres
Bow Wow is hip pop, pop rap
Lil Scrappy is crunk, dirty south rap, southern hip hop, trap music
Lil Wyte is juggalo
Lil Blood stinks and has no genres
Lil Snupe stinks and has no genres
Lil Mama is hip pop
Lil B stinks and has no genres
Lil' Kim is hip pop
Lil Cuete is chicano rap
Lil Phat stinks and has no genres
Lil Debbie stinks and has no genres
Lil Twist is jerk
Lil Trill is deep trap
Lil Twon stinks and has no genres
Lil AJ stinks and has no genres
Lil Lonnie stinks and has no genres
Lil Goofy stinks and has no genres
Mr. Lil One is chicano rap
Lil Haiti stinks and has no genres
Lil Flash stinks and has no genres
Lil Kesh stinks and has no genres
Lil Cray stinks and has no genres
Lil Rue stinks and has no genres
Lil Silva stinks and has no genres
Lil Eddie stinks and has no genres
Lil Boom stinks and has no genres
Lil Yase stinks and has no genres
Lil Wayne, DJ Drama stinks and has no genres
Lil Suzy is freestyle
Lil Mouse stinks and has no genres
Lil C stinks and has no genres
Lil Rick is soca
Lil E stinks and has no genres
Lil June stinks and has no genres
Lil Fate stinks and has no genres
Lil' Flip is crunk, dirty south rap

In [5]:
most_popular={'artist': '???', 'popularity': 0, 'followers': 0}
second_most_popular={'artist': '???', 'popularity': 0, 'followers': 0}
third_most_popular={'artist': '???', 'popularity': 0, 'followers': 0}
most_followers={'artist': '???', 'total': 0}
for artist in artists:
    if artist['popularity'] > most_popular['popularity']:
        most_popular['artist']=artist['name']
        most_popular['popularity']=artist['popularity']
        most_popular['followers']=artist['followers']['total']
    elif artist['popularity'] > second_most_popular['popularity']:
        second_most_popular['artist']=artist['name']
        second_most_popular['popularity']=artist['popularity']
        second_most_popular['followers']=artist['followers']['total']
    elif artist['popularity'] > third_most_popular['popularity']:
        third_most_popular['artist']=artist['name']
        third_most_popular['popularity']=artist['popularity']
        third_most_popular['followers']=artist['followers']['total']
    if artist['followers']['total'] > most_followers['total']:
        most_followers['artist']=artist['name']
        most_followers['total']=artist['followers']['total']
print("The most popular Lil OTHER THAN (obviously) Lil Wayne is:", second_most_popular['artist'])
print("The next most popular Lil after that is:", third_most_popular['artist'])
if most_followers['artist']==most_popular['artist']:
    print(most_followers['artist'], 'also has the most followers with', most_followers['total'])
else:
    print("The artist with the most followers is", most_followers['artist'], 'with', most_followers['total'])


The most popular Lil OTHER THAN (obviously) Lil Wayne is: Lil Yachty
The next most popular Lil after that is: Lil Uzi Vert
Lil Wayne also has the most followers with 2622820

In [6]:
more_popular_than_lil_kim=[]
for artist in artists:
    if int(artist['popularity']) > 62:
        more_popular_than_lil_kim.append(artist['name'])
print("Here's a list of all the lil's more popular than Lil' Kim:", ", ".join(more_popular_than_lil_kim))


Here's a list of all the lil's more popular than Lil' Kim: Lil Wayne, Lil Yachty, Lil Uzi Vert, Lil Dicky, Boosie Badazz, Lil Jon

In [7]:
boozie_badazz=next((artist for artist in artists if artist['name']=="Boosie Badazz"), None)
lil_dicky=next((artist for artist in artists if artist['name']=="Lil Dicky"), None)
response=requests.get('https://api.spotify.com/v1/artists/'+boozie_badazz['id']+'/top-tracks?country=US')
boozie_badazz_top=response.json()
response=requests.get('https://api.spotify.com/v1/artists/'+lil_dicky['id']+'/top-tracks?country=US')
lil_dicky_top=response.json()
print("The two best lil's are Boozie Badazz and Lil Dicky, for what should be obvious reasons.")
print("Here is a list of Boozie Badazz's top tracks:")
for track in boozie_badazz_top['tracks']:
    print(track['name'])
print()
print("And now here is the same manner of thing but with Lil Dicky:")
for track in lil_dicky_top['tracks']:
    print(track['name'])


The two best lil's are Boozie Badazz and Lil Dicky, for what should be obvious reasons.
Here is a list of Boozie Badazz's top tracks:
No Juice
Wipe Me Down [Remix] - feat. Foxx, Webbie and Lil Boosie Explicit
Like A Man (feat. Rich Homie Quan)
Cancer
Set It Off
Smile To Keep From Crying
Crazy
Big Blue Hundreds
Finish U
Smoking On Purple (feat. Webbie)

And now here is the same manner of thing but with Lil Dicky:
$ave Dat Money (feat. Fetty Wap & Rich Homie Quan)
Professional Rapper (feat. Snoop Dogg)
Lemme Freak
Molly (feat. Brendon Urie of Panic at the Disco)
Personality (feat. T Pain)
White Crime
Bruh...
Pillow Talking (feat. Brain)
Who Knew
Oh Well (feat. Jace of Two-9)

In [41]:
explicit={"pop_total": 0, "track_total": 0, "dur_total": 0}
non_explicit={"pop_total": 0, "track_total": 0, "dur_total": 0}
for track in boozie_badazz_top['tracks']:
    if track['explicit']:
        explicit['track_total']=explicit['track_total']+1
        explicit['pop_total']=explicit['pop_total']+track['popularity']
        explicit['dur_total']=explicit['dur_total']+track['duration_ms']
    else:
        non_explicit['track_total']=non_explicit['track_total']+1
        non_explicit['pop_total']=non_explicit['pop_total']+track['popularity']
        non_explicit['dur_total']=non_explicit['dur_total']+track['duration_ms']
if not explicit['track_total']:
    print("Boozie Badazz is a gentleman with no naughty tracks")
else:
    print("Boozie Badass has", explicit['track_total'], "explicit tracks, totaling", format(explicit['dur_total']/60000, '.2f'), "minutes in duration, with an average rating of", explicit['pop_total']/explicit['track_total'])
    if not non_explicit['track_total']:
        print("Boozie Badazz struggles making songs sans swears and therefore has none")
    else:
        print("Boozie Badass has", non_explicit['track_total'], "non-explicit tracks, totaling", format(non_explicit['dur_total']/60000, '.2f'), "minutes in duration, with an average rating of", non_explicit['pop_total']/non_explicit['track_total'])

explicit={"pop_total": 0, "track_total": 0, "dur_total": 0}
non_explicit={"pop_total": 0, "track_total": 0, "dur_total": 0}
for track in lil_dicky_top['tracks']:
    if track['explicit']:
        explicit['track_total']=explicit['track_total']+1
        explicit['pop_total']=explicit['pop_total']+track['popularity']
        explicit['dur_total']=explicit['dur_total']+track['duration_ms']
    else:
        non_explicit['track_total']=non_explicit['track_total']+1
        non_explicit['pop_total']=non_explicit['pop_total']+track['popularity']
        non_explicit['dur_total']=non_explicit['dur_total']+track['duration_ms']
if not explicit['track_total']:
    print("Lil Dicky is a gentleman with no naughty tracks")
else:
    print("Lil Dicky has", explicit['track_total'], "explicit tracks, totaling", format(explicit['dur_total']/60000, '.2f'), "minutes in duration, with an average rating of", explicit['pop_total']/explicit['track_total'])
    if not non_explicit['track_total']:
        print("Lil Dicky struggles making songs sans swears and therefore has none")
    else:
        print("Lil Dicky has", non_explicit['track_total'], "non-explicit tracks, totaling", format(non_explicit['dur_total']/60000, '.2f'), "minutes in duration, with an average rating of", non_explicit['pop_total']/non_explicit['track_total'])


Boozie Badass has 10 explicit tracks, totaling 37.26 minutes in duration, with an average rating of 50.6
Boozie Badazz struggles making songs sans swears and therefore has none
Lil Dicky has 10 explicit tracks, totaling 49.72 minutes in duration, with an average rating of 62.2
Lil Dicky struggles making songs sans swears and therefore has none

In [66]:
lil_response = requests.get('https://api.spotify.com/v1/search?q=Lil&type=artist&limit=50')
raw_lil_data=lil_response.json()
top_50_lils=raw_lil_data['artists']['items']
biggie_response = requests.get('https://api.spotify.com/v1/search?q=Biggie&type=artist&limit=50')
raw_biggie_data=biggie_response.json()
top_50_biggies=raw_biggie_data['artists']['items']

In [61]:
print("There are", raw_lil_data['artists']['total'], "Lils, and", raw_biggie_data['artists']['total'], "Biggies")
print("That's way more Lils")
print("Requesting 1 Lil every 5 seconds is silly but it would also take you", format(raw_lil_data['artists']['total']*5/60, '.2f'), "minutes to get them all")
print("Biggies, meanwhile, would take", format(raw_biggie_data['artists']['total']*5/60, '.2f'), "minutes")


There are 4501 Lils, and 49 Biggies
That's way more Lils
Requesting 1 Lil every 5 seconds is silly but it would also take you 375.08 minutes to get them all
Biggies, meanwhile, would take 4.08 minutes

In [72]:
lil_pop={'count': 0, "total": 0}
biggie_pop={'count': 0, "total": 0}

for lil in top_50_lils:
    lil_pop['count']=lil_pop['count']+1
    lil_pop['total']=lil_pop['total']+lil['popularity']
print("Your average, everyday Lil has a popularity of", lil_pop['total']/lil_pop['count'])
for biggie in top_50_biggies:
    biggie_pop['count']=biggie_pop['count']+1
    biggie_pop['total']=biggie_pop['total']+biggie['popularity']
print("Your average, everyday Biggie has a popularity of", format(biggie_pop['total']/biggie_pop['count'], '.2f'))
print("The lils are clearly winning this war")


Your average, everyday Lil has a popularity of 46.14
Your average, everyday Biggie has a popularity of 3.90

In [ ]: