<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Grade
Step1:  1.Searching and Printing a List of 50 'Lil' Musicians
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.
Step2:  2 Genres Most Represented in the Search Results
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".
Step3:  More Spotify - LIL' GRAPHICS
Use Excel, Illustrator or something like https
Step4:  The Second Highest Popular Artist
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?
Step5:  4. List of Lil's Popular Than Lil' Kim
Step6:  5.Two Favorite Lils and Their Top Tracks
Step7:  6. Average Popularity of My Fav Musicians (Above) for Their explicit songs vs. their non-explicit songs
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?
Step8:  7a.  Number of Biggies and Lils
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?
Step9:  7b. Time to Download All Information on Lil and Biggies
Step10:  8. Highest Average Popular Lils and Biggies Out of The Top 50
<ASSISTANT_TASK:>
Python Code:
import requests
Lil_response = requests.get('https://api.spotify.com/v1/search?query=Lil&type=artist&limit=50&country=US')
Lil_data = Lil_response.json()
#Lil_data
Lil_data.keys()
Lil_data['artists'].keys()
Lil_artists = Lil_data['artists']['items']
Explanation: Grade: 6 / 8 -- check for TA-COMMENTS
End of explanation
#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.
count =0
for artist in Lil_artists:
    count += 1
    print(count,".", artist['name'],"has the popularity of", artist['popularity'])
Explanation: 1.Searching and Printing a List of 50 'Lil' Musicians
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.
End of explanation
# 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
# if len(artist['genres']) == 0 )
# print ("no genres")
# else:
#     genres = ", ".join(artist['genres'])
genre_list = []
genre_loop = Lil_data['artists']['items']
for item in genre_loop:
    #print(item['genres'])
    item_gen = item['genres']
    for i in item_gen:
        genre_list.append(i)
#print(sorted(genre_list))
#COUNTING the most 
genre_counter = {}
for word in genre_list:
    if word in genre_counter:
        genre_counter[word] += 1
    else:
        genre_counter[word] = 1
popular_genre = sorted(genre_counter, key = genre_counter.get, reverse = True)
top_genre = popular_genre[:1]
print("The genre most represented is", top_genre)
#COUNTING the most with count to confirm
from collections import Counter
count = Counter(genre_list)
most_count = count.most_common(1)
print("The genre most represented and the count are", most_count)
print("-----------------------------------------------------")
    
for artist in Lil_artists:
    num_genres = 'no genres listed'
    if len(artist['genres']) > 0:
        num_genres= str.join(',', (artist['genres']))
    print(artist['name'],"has the popularity of", artist['popularity'], ", and has", num_genres, "under genres")
Explanation: 2 Genres Most Represented in the Search Results
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".
End of explanation
Lil_response = requests.get('https://api.spotify.com/v1/search?query=Lil&type=artist&limit=50&country=US')
Lil_data = Lil_response.json()
#Lil_data
Explanation: More Spotify - LIL' GRAPHICS
Use Excel, Illustrator or something like https://infogr.am/ to make a graphic about the Lil's, or the Lil's vs. the Biggies. 
Just a simple bar graph of their various popularities sounds good to me.
Link to the Line Graph of Lil's Popularity chart
Lil Popularity Graph
End of explanation
#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?
name_highest = ""
name_follow =""
second_high_pop = 0
highest_pop = 0
high_follow = 0
for artist in Lil_artists:
    if (highest_pop < artist['popularity']) & (artist['name'] != "Lil Wayne"):
        #second_high_pop = highest_pop
        #name_second = artist['name']
        highest_pop = artist['popularity']
        name_highest = artist['name']
    if (high_follow < artist['followers']['total']):
        high_follow = artist ['followers']['total']
        name_follow = artist['name']
    
    #print(artist['followers']['total'])
print(name_highest, "has the second highest popularity, which is", highest_pop)
print(name_follow, "has the highest number of followers:", high_follow)
#print("the second highest popularity is", second_high_pop)
Lil_response = requests.get('https://api.spotify.com/v1/search?query=Lil&type=artist&limit=50&country=US')
Lil_data = Lil_response.json()
#Lil_data
Explanation: The Second Highest Popular Artist
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?
End of explanation
Lil_artists = Lil_data['artists']['items']
#Print a list of Lil's that are more popular than Lil' Kim.
count = 0
for artist in Lil_artists:
    if artist['popularity'] > 62:
        count+=1
        print(count, artist['name'],"has the popularity of", artist['popularity'])
        
    #else:
        #print(artist['name'], "is less popular with a score of", artist['popularity'])
    
Explanation: 4. List of Lil's Popular Than Lil' Kim
End of explanation
response = requests.get("https://api.spotify.com/v1/search?query=Lil&type=artist&limit=2&country=US")
data = response.json()
for artist in Lil_artists:
    #print(artist['name'],artist['id'])
    if artist['name'] == "Lil Wayne":
        wayne = artist['id']
        print(artist['name'], "id is",wayne) 
        
    if artist['name'] == "Lil Yachty":
        yachty = artist['id']
        print(artist['name'], "id is", yachty)  
#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.
response = requests.get("https://api.spotify.com/v1/artists/" +wayne+ "/top-tracks?country=US")
data = response.json()
tracks = data['tracks']
print("Lil Wayne's top tracks are: ")
for track in tracks:
    print("-", track['name'])
print("-----------------------------------------------")
response = requests.get("https://api.spotify.com/v1/artists/" +yachty+ "/top-tracks?country=US")
data = response.json()
tracks = data['tracks']
print("Lil Yachty 's top tracks are: ")
for track in tracks:
    print("-", track['name'])
Explanation: 5.Two Favorite Lils and Their Top Tracks
End of explanation
response = requests.get("https://api.spotify.com/v1/artists/" +yachty+ "/top-tracks?country=US")
data = response.json()
tracks = data['tracks']
#print(tracks)
#for track in tracks:
    #print(track.keys())
#Get an average popularity for their explicit songs vs. their non-explicit songs. 
#How many minutes of explicit songs do they have? Non-explicit?
# How explicit is Lils?
response = requests.get("https://api.spotify.com/v1/artists/" +yachty+ "/top-tracks?country=US")
data = response.json()
tracks = data['tracks']
# counter for tracks for explicit and clean
track_count = 0 
clean_count = 0
#counter to find avg popularity
popular_exp = 0
popular_clean = 0
#counter for avg time in minutes are below:
timer = 0
data_timer = 0
timer_clean = 0
for track in tracks:
    print("The track,", track['name'],", with the id",track['id'], "is", track['explicit'],"for explicit content, and has the popularity of", track['popularity'])
    track_id = track['id']
    time_ms = track['duration_ms']
    
    # TA-COMMENT: (-1) If what is true? "if True" will always evaluate to True.... 
    if True:
        track_count = track_count + 1
        popular_exp = popular_exp + track['popularity'] # TA-COMMENT: What is this supposed to capture? 
        # It HAPPENS to be the case that all the tracks are explicit, but if that were not true, would this be correct?
        
        response = requests.get("https://api.spotify.com/v1/tracks/" + track_id)
        data_track = response.json()
        print("and has the duration of", data_track['duration_ms'], "milli seconds.")
        timer = timer + time_ms
        timer_minutes = ((timer / (1000*60)) % 60)
    if not track['explicit']:
        clean_count = clean_count + 1
        popular_clean = popular_clean + track['popularity']
        response = requests.get("https://api.spotify.com/v1/tracks/" + track_id)
        data_tracks = response.json()
        timer_clean = timer_clean + time_ms
        timer_minutes_clean = ((data_timer / (1000*60)) % 60)
        print(", and has the duration of", timer_minutes_clean, "minutes")
        
print("------------------------------------")
avg_pop =  popular_exp / track_count
print("I have found", track_count, "tracks, and has the average popularity of", avg_pop, "and has the average duration of", timer_minutes,"minutes and", clean_count, "are clean")
#print("Overall, I discovered", track_count, "tracks")
#print("And", clean_count, "were non-explicit")
#print("Which means", , " percent were clean for Lil Wayne")
# TA-COMMENT: example of what happens if you do just "if True" as in the code above. 
if True: 
    print("hello")
# TA-COMMENT: Same commends apply here. 
#Get an average popularity for their explicit songs vs. their non-explicit songs. 
#How many minutes of explicit songs do they have? Non-explicit?
# How explicit is Lils?
response = requests.get("https://api.spotify.com/v1/artists/" +wayne+ "/top-tracks?country=US")
data = response.json()
# counter for tracks for explicit and clean
track_count = 0 
clean_count = 0
#counter to find avg popularity
popular_exp = 0
popular_clean = 0
#counter for avg time in minutes are below:
timer = 0
#data_timer = 0
timer_clean = 0
for track in tracks:
    print("The track,", track['name'],", with the id",track['id'], "is", track['explicit'],"for explicit content, and has the popularity of", track['popularity'])
    track_id = track['id']
    time_ms = data_track['duration_ms']
    if True:
        track_count = track_count + 1
        popular_exp = popular_exp + track['popularity']
        response = requests.get("https://api.spotify.com/v1/tracks/" + track_id)
        data_track = response.json()
        print("and has the duration of", data_track['duration_ms'], "milli seconds.")
        timer = timer + time_ms
        timer_minutes = ((timer / (1000*60)) % 60)
    if not track['explicit']:
        clean_count = clean_count + 1
        popular_clean = popular_clean + track['popularity']
        response = requests.get("https://api.spotify.com/v1/tracks/" + track_id)
        data_tracks = response.json()
        timer_clean = timer_clean + time_ms
        timer_minutes_clean = ((data_timer / (1000*60)) % 60)
        print(", and has the duration of", timer_minutes_clean, "minutes")
        
print("------------------------------------")
avg_pop =  popular_exp / track_count
print("I have found", track_count, "tracks, and has the average popularity of", avg_pop, "and has the average duration of", timer_minutes,"minutes and", clean_count, "are clean")
#print("Overall, I discovered", track_count, "tracks")
#print("And", clean_count, "were non-explicit")
#print("Which means", , " percent were clean for Lil Wayne")
Explanation: 6. Average Popularity of My Fav Musicians (Above) for Their explicit songs vs. their non-explicit songs
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?
End of explanation
#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?
biggie_response = requests.get('https://api.spotify.com/v1/search?query=biggie&type=artist&country=US')
biggie_data = biggie_response.json()
biggie_artists = biggie_data['artists']['total']
print("Total number of Biggie artists are", biggie_artists)
lil_response = requests.get('https://api.spotify.com/v1/search?query=Lil&type=artist&country=US')
lil_data = lil_response.json()
lil_artists = lil_data['artists']['total']
print("Total number of Lil artists are", lil_artists)
Explanation: 7a.  Number of Biggies and Lils
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?
End of explanation
#If you made 1 request every 5 seconds, how long would it take to download information on all the Lils vs the Biggies?
limit_download = 50
biggie_artists = biggie_data['artists']['total']
Lil_artist = Lil_data['artists']['total']
#1n 5 sec = 50
#in 1 sec = 50 / 5 req = 10 no, for 1 no, 1/10 sec
# for 4501 = 4501/10 sec
# for 49 49/ 10 sec
big_count = biggie_artists/10
lil_count = Lil_artist / 10
print("It would take", big_count, "seconds for Biggies, where as it would take", lil_count,"seconds for Lils" )
# TA-COMMENT: (-1) If one request takes 5 seconds, then 50 requests would take (50 * 5) seconds 
# (one request for each 'Biggie')
# So, 4510 Lil artists would take 4510 * 5 seconds
Explanation: 7b. Time to Download All Information on Lil and Biggies
End of explanation
#Out of the top 50 "Lil"s and the top 50 "Biggie"s, who is more popular on average?
biggie_response = requests.get('https://api.spotify.com/v1/search?query=biggie&type=artist&limit=50&country=US')
biggie_data = biggie_response.json()
biggie_artists = biggie_data['artists']['items']
big_count_pop = 0
for artist in biggie_artists:
    #count_pop = artist['popularity']
    big_count_pop = big_count_pop + artist['popularity']
print("Biggie has a total popularity of ", big_count_pop)
big_pop = big_count_pop / 49
print("Biggie is on an average", big_pop,"popular")
#Lil
Lil_response = requests.get('https://api.spotify.com/v1/search?query=Lil&type=artist&limit=50&country=US')
Lil_data = Lil_response.json()
Lil_artists = Lil_data['artists']['items']
lil_count_pop = 0
for artist in Lil_artists:
    count_pop_lil = artist['popularity']
    lil_count_pop = lil_count_pop + count_pop_lil
lil_pop = lil_count_pop / 50
print("Lil is on an average", lil_pop,"popular")
Explanation: 8. Highest Average Popular Lils and Biggies Out of The Top 50
End of explanation
<END_TASK>