Advertisement
horozov86

Movie organizer

Jun 5th, 2023
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. def movie_organizer(*args):
  2.     film_genres = {}
  3.  
  4.     for movie_name, genre in args:
  5.         if genre not in film_genres:
  6.             film_genres[genre] = []
  7.         film_genres[genre].append(movie_name)
  8.  
  9.     sorted_film_genres = sorted(film_genres.items(), key=lambda x: (-len(x[1]), x[0]))
  10.  
  11.     result = ''
  12.     for genre, movie_name in sorted_film_genres:
  13.         sorted_movies = sorted(movie_name)
  14.         result += f"{genre} - {len(sorted_movies)}\n"
  15.         for name in sorted_movies:
  16.             result += f"* {name}\n"
  17.     return result.strip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement