-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorrections.py
More file actions
69 lines (53 loc) · 2.22 KB
/
corrections.py
File metadata and controls
69 lines (53 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from data import movies
from data import movies
def dramas(movies):
"""
This function takes a list of movies and returns a list of titles
of movies that have 'Drama' in their genres.
:param movies: List of dictionaries, where each dictionary represents a movie.
:return: List of titles of movies with 'Drama' in their genres.
"""
drama_movies = [movie['title'] for movie in movies if 'Drama' in movie['genres']]
return drama_movies
# Get the list of drama movies
drama_movies = dramas(movies)
print(drama_movies)
def findByGenre(genre, movies):
"""
This function takes a genre and a list of movies, and returns a list of titles
of movies that match the specified genre.
:param genre: The genre to search for.
:param movies: List of dictionaries, where each dictionary represents a movie.
:return: List of titles of movies that match the specified genre.
"""
genre_movies = [movie['title'] for movie in movies if genre in movie['genres']]
return genre_movies
# Get the list of action movies
action_movies = findByGenre('Action', movies)
print(action_movies)
def longestMovie(movies):
"""
This function takes a list of movies and returns the movie with the longest runtime.
:param movies: List of dictionaries, where each dictionary represents a movie.
:return: The dictionary representing the movie with the longest runtime.
"""
if not movies:
return None
longest = max(movies, key=lambda movie: movie['runtime'])
return longest
# Get the movie with the longest runtime
longest_movie = longestMovie(movies)
print(longest_movie)
def longestMovieByGenre(genre, movies):
"""
This function takes a genre and a list of movies, and returns the movie with the longest runtime
within the specified genre.
:param genre: The genre to search for.
:param movies: List of dictionaries, where each dictionary represents a movie.
:return: The dictionary representing the movie with the longest runtime in the specified genre.
"""
genre_movies = [movie for movie in movies if genre in movie['genres']]
if not genre_movies:
return None
longest = max(genre_movies, key=lambda movie: movie['runtime'])
return longest