<jupyter_start><jupyter_text>graded = 8/8<jupyter_code>import requests
response = requests.get('https://api.spotify.com/v1/search?q=Lil&type=artist&market=US&limit=50')
Lil = response.json()
print(Lil.keys())
print(type(Lil['artists']))
print(Lil['artists'].keys())
Lil_info = Lil['artists']['items']
print(type(Lil_info))
print(Lil_info[1])<jupyter_output>{'type': 'artist', 'id': '6icQOAFXDZKsumw3YXyusw', 'images': [{'url': 'https://i.scdn.co/image/add25baa69fc7bfd9cfd5d87716941028c2d6736', 'height': 640, 'width': 640}, {'url': 'https://i.scdn.co/image/3f8205117bdd028a648ad3fc925f9fb46dfa26fa', 'height': 300, 'width': 300}, {'url': 'https://i.scdn.co/image/ccc54e2911dbc5463acb401ee61489e27d991408', 'height': 64, 'width': 64}], 'popularity': 73, 'external_urls': {'spotify': 'https://open.spotify.com/artist/6icQOAFXDZKsumw3YXyusw'}, 'followers': {'total': 43484, 'href': None}, 'genres': [], 'href': 'https://api.spotify.com/v1/artists/6icQOAFXDZKsumw3YXyusw', 'uri': 'spotify:artist:6icQOAFXDZKsumw3YXyusw', 'name': '<NAME>'}<jupyter_text>1 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. 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".<jupyter_code>for every_lil in Lil_info:
    print(every_lil['name'], every_lil['popularity'],"Genre:",(", ".join(every_lil['genres'])))
    if every_lil['genres'] == []:
        print("No genres listed")<jupyter_output>Lil Wayne 86 Genre: dirty south rap, pop rap, southern hip hop, trap music
Lil Yachty 73 Genre: 
No genres listed
Lil Uzi Vert 74 Genre: 
No genres listed
Lil Dicky 69 Genre: 
No genres listed
Boosie Badazz 67 Genre: 
No genres listed
Lil Jon 72 Genre: crunk, dirty south rap, southern hip hop
King Lil G 61 Genre: 
No genres listed
Lil Durk 60 Genre: 
No genres listed
Lil Jon & The East Side Boyz 60 Genre: 
No genres listed
Lil Bibby 54 Genre: 
No genres listed
G Herbo 53 Genre: 
No genres listed
Lil Rob 50 Genre: chicano rap, latin hip hop
Lil Reese 50 Genre: 
No genres listed
Bow Wow 57 Genre: hip pop, pop rap
Lil Keke 48 Genre: 
No genres listed
Lil Scrappy 50 Genre: crunk, dirty south rap, southern hip hop, trap music
Lil Wyte 50 Genre: juggalo
Lil Blood 46 Genre: 
No genres listed
Lil Snupe 45 Genre: 
No genres listed
Lil Mama 45 Genre: hip pop
Lil Boom 46 Genre: 
No genres listed
Lil B 44 Genre: 
No genres listed
Lil' Kim 62 Genre: hip pop
Lil Cuete 40 Genre: chicano rap
Lil Phat [...]<jupyter_text>2) What genres are most represented in the search results?<jupyter_code>genres = []
for item in Lil_info:
    genres = item['genres'] + genres
print(genres)

unique_genres = set(genres)
for every_genre in unique_genres:

    print(every_genre , genres.count(every_genre))
    

#genre_name = set(every_genre)
#genre_number = set(genres.count(every_genre))
    #print(genre_name)
       
       
#this is the other option I did it with soma's help
from collections import Counter

# genres is a long list of genres with a lot repeats
genre_counter = Counter(genres)
genre_counter

counts = Counter(all_genres)
counts.most_common(1)

genre_counter.most_common(3)
#class review. Other option:
#aggregation problem

all_genres = []

for artist in Lil_info:
    #conditional
    print('All genres we have', all_genres)
    print("Current artist has", artist['genres'])
    all_genres = all_genres + artist['genres']
    
print('!!!!All the genres we have are:')
print(all_genres)

all_genres.count("hip pop")
    
    
unique_genre = set(all_genres)
for genre in unique_genres:
    genre_count = all_genres.count(genre)
    print(genre, "shows up", genre_count, "times")
#we have to convert it into a set<jupyter_output>pop rap shows up 2 times
latin hip hop shows up 1 times
crunk shows up 3 times
dirty south rap shows up 4 times
soca shows up 1 times
deep trap shows up 1 times
freestyle shows up 1 times
chicano rap shows up 3 times
juggalo shows up 1 times
hip pop shows up 3 times
southern hip hop shows up 3 times
trap music shows up 2 times
jerk shows up 1 times<jupyter_text>3 Use a for loop to determine who <NAME> has the highest popularity rating. Is it the same artist who has the largest number of followers?<jupyter_code>most_popular = 0
artist_name = Lil
for artist_popularity in Lil_info:
    if artist_popularity['popularity'] == 86:
        most_popular = most_popular
        artist_name = artist_name
    elif artist_popularity['popularity'] > most_popular:
        most_popular = artist_popularity['popularity']
        artist_name = artist_popularity['name']
        
print("Our second most popular artist is", artist_name , "with a popularity score of", most_popular)


most_followers = 0
artist_name = Lil
for artist_followers in Lil_info:
    if artist_followers['followers']['total'] > 0:
        most_followers = artist_followers['followers']['total']
        artist_name = artist_followers['name']
    else:
        most_followers = most_followers
        artist_name = artist_name
    
print("Our artist with the most followers is not the most popular, it is", artist_name , "with ", most_followers, "followers")
#class review. Soma used ---> artist['name'] != '<NAME>':

second_most_popular_name = ""
second_most_popular_score = 0
for artist in Lil_info:
    #this is the conditional
    if artist['popularity'] > second_most_popular_score and artist['name'] != '<NAME>':
    #these are the changes
        second_most_popular_name = artist['name']
        second_most_popular_score = artist['popularity']
print(second_most_popular_name,second_most_popular_score)
#class review. he answered the question of what to do if two people have the same popularity scores
target_score = 72
#initial condition

second_best_artist = []
for artist in Lil_info:
    print("Looking at", artist['name'], "who has a popularity of", artist['popularity'])
    #conditional 
    if artist['popularity'] == 72:
        #change, add new artist to the list where <NAME> is already in. We do that with .append(new thing)
        print("!!!!!!!the artist popularity is 72")
        second_best_artist.append(artist['name'])

print("Our second best artists are:")
for artist in second_best_artist:
    print(artist)<jupyter_output>Looking at <NAME> who has a popularity of 86
Looking at <NAME> who has a popularity of 73
Looking at <NAME> who has a popularity of 74
Looking at <NAME> who has a popularity of 69
Looking at <NAME> who has a popularity of 67
Looking at <NAME> who has a popularity of 72
!!!!!!!the artist popularity is 72
Looking at King <NAME> who has a popularity of 61
Looking at <NAME> who has a popularity of 60
Looking at <NAME> & The East Side Boyz who has a popularity of 60
Looking at <NAME> who has a popularity of 54
Looking at <NAME> who has a popularity of 53
Looking at <NAME> who has a popularity of 50
Looking at <NAME> who has a popularity of 50
Looking at <NAME> who has a popularity of 57
Looking at Lil Keke who has a popularity of 48
Looking at Lil Scrappy who has a popularity of 50
Looking at Lil Wyte who has a popularity of 50
Looking at Lil Blood who has a popularity of 46
Looking at Lil Snupe who has a popularity of 45
Looking at Lil Mama who has a popu[...]<jupyter_text>4) Print a list of Lil's that are more popular than Lil' Kim.<jupyter_code>for artist in Lil_info:
    #print("Looking at", artist['name'])
    if artist['name'] == "<NAME>":
        print("Found Lil' Kim")
        print(artist['popularity'])
    else:
        pass #to keep it from breaking
        #print("NOT Lil' Kim)
#aggregation problem
more_popular_lil_kim = []

#the loop

for artist in Lil_info:
    #the conditional if artist is more popular than lil kim
    if artist['popularity'] > 62:
        print(artist['name'],"is more popular than <NAME> with a score of", artist['popularity'])
        more_popular_lil_kim.append(artist['name'])
print(more_popular_lil_kim)

        
for artist_name in more_popular_lil_kim:
    print(artist_name)

more_popular_string = ", ".join(more_popular_lil_kim)
print("artists more popular than lil kim are:", more_popular_string)<jupyter_output><NAME>
<NAME>
<NAME>
<NAME>
<NAME>
<NAME>
artists more popular than lil kim are: <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME><jupyter_text>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.<jupyter_code>for two_lil in Lil_info:
    print(two_lil['name'], "ID:", two_lil['id'])
import requests
response = requests.get('https://api.spotify.com/v1/artists/6JUnsP7jmvYmdhbg7lTMQj/top-tracks?country=US')
lil_fate = response.json()

print(lil_fate)
print(type(lil_fate))
print(lil_fate.keys())
print(type(lil_fate['tracks']))
lil_fate_top_tracks = lil_fate['tracks']
print(lil_fate_top_tracks)
for top_tracks in lil_fate_top_tracks:
    print("Lil Fate top track is/are", top_tracks['name'])
import requests
response = requests.get('https://api.spotify.com/v1/artists/6L3x3if9RVimruryD9LoFb/top-tracks?country=US')
king_lil = response.json()

print(type(king_lil))
print(king_lil.keys())
king_lil_top_tracks = king_lil['tracks']
print(king_lil_top_tracks)
print("King Lil top track is/are:")
for top_tracks in king_lil_top_tracks:
    print(top_tracks['name'])
for top_tracks in lil_fate_top_tracks:
    print("Lil Fate top track is/are:")
    print("-",top_tracks['name'])
print("King Lil top track is/are:")
for top_tracks in king_lil_top_tracks:
    print("-",top_tracks['name'])<jupyter_output>Lil Fate top track is/are:
- Break A N**a Off
King Lil top track is/are:
- Hopeless Boy (feat. <NAME>)
- Ignorance
- Ak47
- Grow Up (feat. Chikk)
- Cold Christmas
- Welcome to La
- After My Death
- Windows Down (feat. Drummer Boy)
- Room Full Of Smoke
- Narco Corridos<jupyter_text>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?<jupyter_code>import requests
response = requests.get('https://api.spotify.com/v1/artists/6JUnsP7jmvYmdhbg7lTMQj/top-tracks?country=US')
lil_fate = response.json()

explicit_count = 0 
non_explicit_count = 0
popularity_explicit = 0
popularity_non_explicit= 0
minutes_explicit = 0
minutes_non_explicit = 0

for track in lil_fate_top_tracks:   
    
    if track['explicit'] == True:
        explicit_count = explicit_count + 1
        popularity_explicit = popularity_explicit + track['popularity']
        minutes_explicit = minutes_explicit + track['duration_ms']
        print("There is", explicit_count, "explicit track with a popularity of", popularity_explicit)
     
    elif track['explicit'] == False:
        non_explicit_count = non_explicit_count + 1
        popularity_non_explicit = popularity_non_explicit + track['popularity']
        minutes_non_explicit = minutes_non_explicit + track['duration_ms']
        print("There is", non_explicit_count ,"non-explicit track with a popularity of", popularity_non_explicit)

print("The average popularity of Lil Fate explicits songs is", popularity_explicit/explicit_count)   
#Code below--> dividing it by zero because there are no non-explicit counts so it does not work
#print("The average popularity of Lil Fate non-explicits songs is", popularity_non_explicit/non_explicit_count)
print("Lil fate has", (minutes_explicit / 1000) /60 , "minutes of explicit music") #sounds weird. Not sure why I get this result
print("Lil fate has", (minutes_non_explicit / 1000) / 60, "minutes of non-explicit music")#sounds weird. Not sure why I get this result
import requests
response = requests.get('https://api.spotify.com/v1/artists/6L3x3if9RVimruryD9LoFb/top-tracks?country=US')
king_lil = response.json()

explicit_count = 0 
non_explicit_count = 0
popularity_explicit = 0
popularity_non_explicit= 0
minutes_explicit = 0
minutes_non_explicit = 0

for track in king_lil_top_tracks:    
    if track['explicit'] == True:
        explicit_count = explicit_count + 1
        popularity_explicit = popularity_explicit + track['popularity']
        minutes_explicit = minutes_explicit + track['duration_ms']
        print("There is", explicit_count, "explicit track with a popularity of", popularity_explicit)
    

    elif track['explicit'] == False:
        non_explicit_count = non_explicit_count + 1
        popularity_non_explicit = popularity_non_explicit + track['popularity']
        minutes_non_explicit = minutes_non_explicit + track['duration_ms']
        print("There is", non_explicit_count ,"non-explicit track with a popularity of", popularity_non_explicit)


print("The average popularity of King lil explicits songs is", popularity_explicit/explicit_count)
print("The average popularity of King lil non-explicits songs is", popularity_non_explicit/non_explicit_count)
print("Lil King has", (minutes_explicit / 1000) / 60, "minutes of explicit music") #this number does not make sense but not sure what is wrong
print("Lil King has", (minutes_non_explicit /1000) / 60, "minutes of non-explicit music")#sounds weird. Not sure why I get this result<jupyter_output>There is 1 explicit track with a popularity of 55
There is 2 explicit track with a popularity of 109
There is 3 explicit track with a popularity of 163
There is 4 explicit track with a popularity of 216
There is 5 explicit track with a popularity of 268
There is 6 explicit track with a popularity of 318
There is 7 explicit track with a popularity of 368
There is 8 explicit track with a popularity of 418
There is 9 explicit track with a popularity of 467
There is 1 non-explicit track with a popularity of 49
The average popularity of King lil explicits songs is 51.888888888888886
The average popularity of King lil non-explicits songs is 49.0
Lil King has 30.395683333333334 minutes of explicit music
Lil King has 4.1335500000000005 minutes of non-explicit music<jupyter_text>7) Since we're talking about Lils, what about Biggies? How many total "Biggie" artists are there? How many total "Lil"s?<jupyter_code>response = requests.get('https://api.spotify.com/v1/search?q=Lil&type=artist&market=US')
all_lil = response.json()
print(all_lil.keys())
print(all_lil['artists'].keys())
print(all_lil['artists']['total'])
response = requests.get('https://api.spotify.com/v1/search?q=Biggie&type=artist&market=US')
all_biggies = response.json()
print(all_biggies['artists']['total'])<jupyter_output>50<jupyter_text>7.2) If you made 1 request every 5 seconds, how long would it take to download information on all the Lils vs the Biggies?<jupyter_code>response = requests.get('https://api.spotify.com/v1/search?q=Lil&type=artist&market=US')
all_lil = response.json()
total_lils= all_lil['artists']['total']
#print(total_lils)
print("It would take",(total_lils/20) * 5, "to download all the Lils")
response = requests.get('https://api.spotify.com/v1/search?q=Biggie&type=artist&market=US')
all_biggies = response.json()
total_biggies= all_biggies['artists']['total']
#print(total_biggies)
print("It would take",(total_biggies/20) * 5, "to download all the Lils")<jupyter_output>It would take 12.5 to download all the Lils<jupyter_text>8) Out of the top 50 "Lil"s and the top 50 "Biggie"s, who is more popular on average?<jupyter_code>response = requests.get('https://api.spotify.com/v1/search?q=Biggie&type=artist&market=US&limit=50')
biggies = response.json()
print(biggies['artists'].keys())
print(biggies['artists']['items'][0])
import math
biggies_info = biggies['artists']['items']
biggie_total= 0
biggie_popularity= 0
for biggie in biggies_info:
    biggie_total= biggie_total + 1
    biggie_popularity = biggie_popularity + biggie['popularity']
print("The top 50 Biggies have an average score of popularity of", math.ceil(biggie_popularity / biggie_total))
import requests
response = requests.get('https://api.spotify.com/v1/search?q=Lil&type=artist&market=US&limit=50')
Lil = response.json()
import math
Lil_info = Lil['artists']['items']
lil_total= 0
lil_popularity= 0
for lil in Lil_info:
    lil_total= lil_total + 1
    lil_popularity = lil_popularity + lil['popularity']
print("The top 50 Lils have an average score of popularity of", math.ceil(lil_popularity / lil_total))<jupyter_output>The top 50 Lils have an average score of popularity of 47<jupyter_text>Lils Graphic<jupyter_code>#This is the link to my graphic of the various popularities.
#https://infogr.am/fd7c85b9-f59b-498d-829d-a6ead4fb6862<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10196597126194913, 'fraction_numerical': 0.02741537906571274, 'mean_word_length': 4.99207492795389, 'pattern_counts': {'":': 1, '<': 69, '<?xml version=': 0, '>': 75, 'https://': 17, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '434188', 'license': 'MIT', 'n_tokens_mistral': 5965, 'n_tokens_neox': 5474, 'n_words': 1792, 'path': 'foundations_hw/05/Homework_5_Spotify_graded.ipynb', 'repo_name': 'mercybenzaquen/foundations-homework', 'size': '16750'}