on txt file containing the fallawing:
Tudo Bom;Static and Ben El Tavori;5:13;
I Gotta Feeling;The Black Eyed Peas;4:05;
Instrumental;Unknown;4:15;
Paradise;Coldplay;4:23;
Where is the love?;The Black Eyed Peas;4:13;
i'm trying to use this simple program:
def my_mp3_playlist(file_path):
with open(file_path, 'r') as playlist_file:
result_playlist_tuple = tuple() # Result tuple
playlist_splitted_lines = playlist_file.readlines()#.split("\n") # List of songs and additional data
len_of_playlist_splitted_lines = len(playlist_splitted_lines) # Getting list length instead of running a
# loop len(x) times
playlist_items = list()
for line in range(len_of_playlist_splitted_lines): # Extracting list of items from list of lines
playlist_items.append(playlist_splitted_lines[line].split(';'))
for element in playlist_items: # Deleting empty strings '' in playlist_lines
del element[-1]
del playlist_items[-1]
max_song_length, longest_song_name = 0, ""
max_artist_appearances, most_appearing_artist = 0, ""
for i in playlist_items:
# Getting max song length
curr_float_song_length = float(i[-1].replace(':', '.'))
if curr_float_song_length > max_song_length: # Getting max song length
max_song_length = curr_float_song_length
longest_song_name = i[0]
if i.count(i[1]) > max_artist_appearances: # Getting Most appearing song
max_artist_appearances = playlist_items.count(i)
most_appearing_artist = i[1]
result_playlist_tuple += (longest_song_name, len(playlist_items), most_appearing_artist)
return result_playlist_tuple
def main():
file_path = input("Enter file path: ")
print(my_mp3_playlist(file_path))
if __name__ == '__main__':
main()
program need to return tuple: (str:longest_song, int:playlist_items(lines), str:most_appearing_artist)
output i want: ("Tudo Bom", 5, "The black Eyed Peas")
otput i get: ('Tudo Bom', 3, 'Static and Ben El Tavori')*
please help, thanks ahead, Eyal.