Advertisement
IMustRemainUnknown

Frank Lee The Great

Nov 23rd, 2023
742
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.65 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. }
  8.  
  9.  
  10. def add_song(song_title, song_artist, album, release_date, genre):
  11.     dict_count = len(song_dictionary) + 1
  12.     song_dictionary['song' + str(dict_count)] = {'title': song_title,
  13.                                                  'artist': song_artist,
  14.                                                  'album': [album],
  15.                                                  'release_date': release_date,
  16.                                                  'genre': [genre]}
  17.  
  18.  
  19. def print_all_unique_genre():
  20.     # Extracting unique genres
  21.     unique_genres = set()
  22.     for movie_info in song_dictionary.values():
  23.         unique_genres.update(movie_info.get('genre', []))
  24.  
  25.     # Printing unique genres
  26.     print('Unique Genres:', unique_genres)
  27.  
  28. def print_all_unique_albums():
  29.     # Extracting unique genres
  30.     unique_albums = set()
  31.     for movie_info in song_dictionary.values():
  32.         unique_albums.update(movie_info.get('album', []))
  33.  
  34.     # Printing unique genres
  35.     print('Unique Albums:', unique_albums)
  36.  
  37.  
  38. def print_album_songs():
  39.     # Extracting unique genres
  40.     unique_genres = set()
  41.     for movie_info in song_dictionary.values():
  42.         unique_genres.update(movie_info.get('genres', []))
  43.  
  44.     # Printing unique genres
  45.     print('Unique Genres:', unique_genres)
  46.  
  47.  
  48. def print_title_artist_date():
  49.     for song_id, song_info in song_dictionary.items():
  50.         title = song_info['title']
  51.         artist = song_info['artist']
  52.         release_date = song_info['release_date']
  53.         print(f"{title}\t{artist}\t{release_date}")
  54.  
  55.  
  56. def print_song_released_after_2010():
  57.     # Print song titles released after the year 2010
  58.     for song_id, song_info in song_dictionary.items():
  59.         title = song_info['title']
  60.         release_date = song_info['release_date']
  61.  
  62.         # Check if the release year is known and greater than 2010
  63.         if release_date > 2010:
  64.             print(f"{title} (Released in {release_date})")
  65.  
  66.  
  67. print(song_dictionary)
  68. print('--------------------------------------------------------------------------------------')
  69. add_song('Adore You', 'Harry Styles', 'Fine Line', 2019, 'Funk, Disco, Pop Rock')
  70. add_song('A Thousand Miles', 'Vanessa Cariton', 'Be Not Nobody', 2002, 'Pop')
  71. add_song('Lover', 'Taylor Swift', 'Lover', 2019, 'Country, Indie Folk, Alternative Country')
  72. print(song_dictionary)
  73. print_all_unique_genre()
  74. print_all_unique_albums()
  75. print_title_artist_date()
  76. print_song_released_after_2010()
  77.  
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement