Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- song_dictionary = {
- 'song1': {'title': 'Bad Day',
- 'artist': 'Daniel Powter',
- 'album': ['Daniel Powter'],
- 'release_date': 2005,
- 'genre': ['Pop'],
- 'duration': 235,
- 'producer': 'Mitchell Froom, Jeff Dawson',
- 'songwriter': 'Daniel Powter'}
- }
- def add_song(song_title, song_artist, album, release_date, genre, duration, producer, songwriter):
- dict_count = len(song_dictionary) + 1
- song_dictionary['song' + str(dict_count)] = {'title': song_title,
- 'artist': song_artist,
- 'album': [album],
- 'release_date': release_date,
- 'genre': [genre],
- 'duration': duration,
- 'producer': producer,
- 'songwriter': songwriter}
- def print_all_unique_genre():
- # Extracting unique genres
- unique_genres = set()
- for movie_info in song_dictionary.values():
- unique_genres.update(movie_info.get('genre', []))
- # Printing unique genres
- print('Unique Genres:', unique_genres)
- def print_all_unique_albums():
- # Extracting unique genres
- unique_albums = set()
- for movie_info in song_dictionary.values():
- unique_albums.update(movie_info.get('album', []))
- # Printing unique genres
- print('Unique Albums:', unique_albums)
- def print_album_songs():
- # Extracting unique genres
- unique_genres = set()
- for movie_info in song_dictionary.values():
- unique_genres.update(movie_info.get('genres', []))
- # Printing unique genres
- print('Unique Genres:', unique_genres)
- def print_title_artist_date():
- for song_id, song_info in song_dictionary.items():
- title = song_info['title']
- artist = song_info['artist']
- release_date = song_info['release_date']
- print(f"{title}\t{artist}\t{release_date}")
- def print_song_released_after_2010():
- # Print song titles released after the year 2010
- for song_id, song_info in song_dictionary.items():
- title = song_info['title']
- release_date = song_info['release_date']
- # Check if the release year is known and greater than 2010
- if release_date > 2010:
- print(f"{title} (Released in {release_date})")
- def print_pop_songs():
- # Print song titles that are Pop songs
- for song_id, song_info in song_dictionary.items():
- title = song_info['title']
- genres = song_info['genre']
- # Check if 'Pop' is in the list of genres
- if 'Pop' in genres:
- print(title)
- def print_genre(target_genre):
- print('Songs under ' + target_genre + ' genre:')
- for song_id, song_info in song_dictionary.items():
- title = song_info['title']
- genres = song_info['genre']
- # Check if the target_genre is in the list of genres
- if target_genre in genres:
- print(title)
- def print_highest_duration():
- max_duration_song = max(song_dictionary.values(), key=lambda x: x['duration'])
- print(f"Title: {max_duration_song['title']}")
- print(f"Duration: {max_duration_song['duration']} seconds")
- def print_lover_songs():
- # Print songs that belong to the album "Lover"
- for song_id, song_info in song_dictionary.items():
- if 'Lover' in song_info['album']:
- print(song_info['title'])
- def print_album_songs(target_album):
- album_songs = []
- for song_id, song_info in song_dictionary.items():
- if target_album in song_info['album']:
- album_songs.append(song_info['title'])
- print(album_songs)
- def print_all_unique_albums_songs():
- # Create a dictionary to store songs by album
- songs_by_album = {}
- # Group songs by album
- for song_id, song_info in song_dictionary.items():
- for album in song_info['album']:
- if album not in songs_by_album:
- songs_by_album[album] = []
- songs_by_album[album].append(song_info['title'])
- # Print songs by album
- for album, songs in songs_by_album.items():
- print(f"{album} {songs}")
- add_song('Adore You', 'Harry Styles', 'Fine Line', 2019, 'Funk, Disco, Pop Rock', 207, 'Kid Harpoon', 'Harry Styles, Amy Allen, Tyl Johnson, Kid Harpoon')
- add_song('A Thousand Miles', 'Vanessa Cariton', 'Be Not Nobody', 2002, 'Pop', 240, 'Ron Fair, Curtis Schweitzer', 'Vanessa Cariton')
- add_song('Lover', 'Taylor Swift', 'Lover', 2019, 'Country, Indie Folk, Alternative Country', 221, 'Taylor Swift, Jack Antonoff', 'Taylor Swift')
- add_song('Cornelia', 'Taylor Swift', 'Lover', 2019, 'Electropop',287, 'Taylor Swift, Jack Antonoff', 'Taylor Swift')
- print('---------------UNIQUE GENRES---------------')
- print_all_unique_genre()
- print()
- print('---------------UNIQUE ALBUMS---------------')
- print_all_unique_albums()
- print()
- print('---------------PRINTING SONG, ARTIST, and RELEASED DATE---------------')
- print_title_artist_date()
- print()
- print('---------------SONG RELEASED AFTER 2010---------------')
- print_song_released_after_2010()
- print()
- print('---------------POP SONGS---------------')
- print_pop_songs()
- print()
- print('---------------PRINT GENRE---------------')
- print_genre("Electropop")
- print()
- print('---------------PRINT HIGHEST DURATION---------------')
- print_highest_duration()
- print()
- print('---------------PRINT SONGS UNDER LOVER ALBUM---------------')
- print_lover_songs()
- print()
- print('---------------PRINT ALBUM SONGS---------------')
- print_album_songs('Lover')
- print()
- print('---------------PRINT EACH UNIQUE ALBUM SONGS---------------')
- print_all_unique_albums_songs()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement