Advertisement
IMustRemainUnknown

Basic Shit

Nov 23rd, 2023 (edited)
1,041
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.85 KB | Source Code | 0 0
  1. song_dictionary = {
  2.     'song1': {'title': 'Bad Day',
  3.               'artist': 'Daniel Powter',
  4.               'album': ['Daniel Powter'],
  5.               'release_date': 2005,
  6.               'genre': ['Pop'],
  7.               'duration': 235,
  8.               'producer': 'Mitchell Froom, Jeff Dawson',
  9.               'songwriter': 'Daniel Powter'}
  10. }
  11.  
  12.  
  13. def add_song(song_title, song_artist, album, release_date, genre, duration, producer, songwriter):
  14.     dict_count = len(song_dictionary) + 1
  15.     song_dictionary['song' + str(dict_count)] = {'title': song_title,
  16.                                                  'artist': song_artist,
  17.                                                  'album': [album],
  18.                                                  'release_date': release_date,
  19.                                                  'genre': [genre],
  20.                                                  'duration': duration,
  21.                                                  'producer': producer,
  22.                                                  'songwriter': songwriter}
  23.  
  24.  
  25. def print_all_unique_genre():
  26.     # Extracting unique genres
  27.     unique_genres = set()
  28.     for movie_info in song_dictionary.values():
  29.         unique_genres.update(movie_info.get('genre', []))
  30.  
  31.     # Printing unique genres
  32.     print('Unique Genres:', unique_genres)
  33.  
  34.  
  35. def print_all_unique_albums():
  36.     # Extracting unique genres
  37.     unique_albums = set()
  38.     for movie_info in song_dictionary.values():
  39.         unique_albums.update(movie_info.get('album', []))
  40.  
  41.     # Printing unique genres
  42.     print('Unique Albums:', unique_albums)
  43.  
  44.  
  45. def print_album_songs():
  46.     # Extracting unique genres
  47.     unique_genres = set()
  48.     for movie_info in song_dictionary.values():
  49.         unique_genres.update(movie_info.get('genres', []))
  50.  
  51.     # Printing unique genres
  52.     print('Unique Genres:', unique_genres)
  53.  
  54.  
  55. def print_title_artist_date():
  56.     for song_id, song_info in song_dictionary.items():
  57.         title = song_info['title']
  58.         artist = song_info['artist']
  59.         release_date = song_info['release_date']
  60.         print(f"{title}\t{artist}\t{release_date}")
  61.  
  62.  
  63. def print_song_released_after_2010():
  64.     # Print song titles released after the year 2010
  65.     for song_id, song_info in song_dictionary.items():
  66.         title = song_info['title']
  67.         release_date = song_info['release_date']
  68.  
  69.         # Check if the release year is known and greater than 2010
  70.         if release_date > 2010:
  71.             print(f"{title} (Released in {release_date})")
  72.  
  73.  
  74. def print_pop_songs():
  75.     # Print song titles that are Pop songs
  76.     for song_id, song_info in song_dictionary.items():
  77.         title = song_info['title']
  78.         genres = song_info['genre']
  79.  
  80.         # Check if 'Pop' is in the list of genres
  81.         if 'Pop' in genres:
  82.             print(title)
  83.  
  84.  
  85. def print_genre(target_genre):
  86.  
  87.     print('Songs under ' + target_genre + ' genre:')
  88.  
  89.     for song_id, song_info in song_dictionary.items():
  90.         title = song_info['title']
  91.         genres = song_info['genre']
  92.  
  93.         # Check if the target_genre is in the list of genres
  94.         if target_genre in genres:
  95.             print(title)
  96.  
  97.  
  98. def print_highest_duration():
  99.     max_duration_song = max(song_dictionary.values(), key=lambda x: x['duration'])
  100.     print(f"Title: {max_duration_song['title']}")
  101.     print(f"Duration: {max_duration_song['duration']} seconds")
  102.  
  103.  
  104. def print_lover_songs():
  105.     # Print songs that belong to the album "Lover"
  106.     for song_id, song_info in song_dictionary.items():
  107.         if 'Lover' in song_info['album']:
  108.             print(song_info['title'])
  109.  
  110.  
  111. def print_album_songs(target_album):
  112.     album_songs = []
  113.     for song_id, song_info in song_dictionary.items():
  114.         if target_album in song_info['album']:
  115.             album_songs.append(song_info['title'])
  116.  
  117.     print(album_songs)
  118.  
  119.  
  120. def print_all_unique_albums_songs():
  121.     # Create a dictionary to store songs by album
  122.     songs_by_album = {}
  123.  
  124.     # Group songs by album
  125.     for song_id, song_info in song_dictionary.items():
  126.         for album in song_info['album']:
  127.             if album not in songs_by_album:
  128.                 songs_by_album[album] = []
  129.             songs_by_album[album].append(song_info['title'])
  130.  
  131.     # Print songs by album
  132.     for album, songs in songs_by_album.items():
  133.         print(f"{album} {songs}")
  134.  
  135.  
  136. add_song('Adore You', 'Harry Styles', 'Fine Line', 2019, 'Funk, Disco, Pop Rock', 207, 'Kid Harpoon', 'Harry Styles, Amy Allen, Tyl Johnson, Kid Harpoon')
  137. add_song('A Thousand Miles', 'Vanessa Cariton', 'Be Not Nobody', 2002, 'Pop', 240, 'Ron Fair, Curtis Schweitzer', 'Vanessa Cariton')
  138. add_song('Lover', 'Taylor Swift', 'Lover', 2019, 'Country, Indie Folk, Alternative Country', 221, 'Taylor Swift, Jack Antonoff', 'Taylor Swift')
  139. add_song('Cornelia', 'Taylor Swift', 'Lover', 2019, 'Electropop',287, 'Taylor Swift, Jack Antonoff', 'Taylor Swift')
  140.  
  141. print('---------------UNIQUE GENRES---------------')
  142. print_all_unique_genre()
  143.  
  144. print()
  145. print('---------------UNIQUE ALBUMS---------------')
  146. print_all_unique_albums()
  147.  
  148. print()
  149. print('---------------PRINTING SONG, ARTIST, and RELEASED DATE---------------')
  150. print_title_artist_date()
  151.  
  152. print()
  153. print('---------------SONG RELEASED AFTER 2010---------------')
  154. print_song_released_after_2010()
  155.  
  156. print()
  157. print('---------------POP SONGS---------------')
  158. print_pop_songs()
  159.  
  160. print()
  161. print('---------------PRINT GENRE---------------')
  162. print_genre("Electropop")
  163.  
  164. print()
  165. print('---------------PRINT HIGHEST DURATION---------------')
  166. print_highest_duration()
  167.  
  168. print()
  169. print('---------------PRINT SONGS UNDER LOVER ALBUM---------------')
  170. print_lover_songs()
  171.  
  172. print()
  173. print('---------------PRINT ALBUM SONGS---------------')
  174. print_album_songs('Lover')
  175.  
  176. print()
  177. print('---------------PRINT EACH UNIQUE ALBUM SONGS---------------')
  178. print_all_unique_albums_songs()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement