• A MovieList is a doubly linked list in which each element of the list is a MovieNode • A MovieNode has the following attributes: o title: a string, the title of the movie o year: an integer for the year the movie was first released o director: a string, the name of the director of the movie o genre: a string, the genre (or category of the movie) e.g. comedy, drama, action o next: a reference to the next MovieNode in the list, or None if it is the last in the list o prev: a reference to the previous MovieNode, or None if it is the first in the list Task : Complete the method remove_movie(self, movie) • Input to the method is a MovieObject • The method removes that MovieObject from the list You are provided with code in __main___ for testing which prompts the user for a number of movies to remove, finds the MovieNode with that title in the MovieList. and removes it For example, if the list contained the following movies, printed using the MovieList method display(): Title: Point Break Title: The Power of the Dog Title: Hunt for the Wilderpeople Title: Jojo Rabbit Title: Promising Young Woman Title: The Piano removing the movies with the following titles: Point Break Jojo Rabbit would result in the following MovieList Title: The Power of the Dog Title: Hunt for the Wilderpeople Title: Promising Young Woman The Piano Title: Year: 1991 Year: 2021 Year: 2016 Year: 2019 Year: 2020 Year: 1993 Year: 2021 Year: 2016 Year: 2020 Year: 1993 Director: Kathryn Bigelow Director: Jane Campion Director: Taika Waititi Director: Taika Waititi Director: Emerald Fennell Director: Jane Campion Director: Jane Campion Director: Taika Waititi Director: Emerald Fennell Director: Jane Campion Genre: action Genre: drama Genre: comedy Genre: comedy Genre: comedy Genre: drama Genre: drama Genre: comedy Genre: comedy Genre: drama
Python Code:
###########################################
class MovieNode:
def __init__(self, title, year, director, genre):
self.title = title
self.year = year
self.director = director
self.genre = genre
self.next = None
self.prev = None
def __str__(self):
return f"Title: {self.title:<25} Year: {self.year:<6} Director: {self.director:<20} Genre: {self.genre:<10}"
def __lt__(self, other):
if self.title < other.title:
return True
else:
return False
###########################################
class MovieList:
def __init__(self):
self.head = None
self.tail = None
def display(self):
curr = self.head
while curr:
print(curr)
curr = curr.next
# Append new_movie at end of MovieList
def append_movie(self, new_movie): # simply adding book to the end of the ddl
if self.head == None:
self.head = new_movie
self.tail = new_movie
else:
self.tail.next = new_movie
new_movie.prev = self.tail
self.tail = new_movie
# Insert new_movie after curr_movie
def insert_movie_after(self, curr_movie, new_movie):
if self.head is None:
self.head = new_movie
self.tail = new_movie
elif curr_movie is self.tail:
self.tail.next = new_movie
new_movie.prev = self.tail
self.tail = new_movie
else:
succ = curr_movie.next
new_movie.next = succ
new_movie.prev = curr_movie
curr_movie.next = new_movie
succ.prev = new_movie
def get_movie(self,title):
curr = self.head
while curr and curr.title != title:
curr = curr.next
return curr
#################################################
# Task 1: implement remove_movie function
#################################################
def remove_movie(self, movie):
#
# your code goes here
#
pass # fix this
if __name__ == "__main__":
movies = MovieList()
movies.append_movie(MovieNode('Point Break', 1991,'Kathryn Bigelow', 'action'))
movies.append_movie(MovieNode('The Power of the Dog', 2021, 'Jane Campion','drama'))
movies.append_movie(MovieNode('Hunt for the Wilderpeople', 2016,'Taika Waititi', 'comedy'))
movies.append_movie(MovieNode('Jojo Rabbit', 2019, 'Taika Waititi', 'comedy'))
movies.append_movie(MovieNode('Promising Young Woman', 2020, 'Emerald Fennell','comedy'))
movies.append_movie(MovieNode('The Piano',1993,'Jane Campion','drama'))
num_to_remove = int(input())
for n in range(num_to_remove):
to_remove = input()
movie = movies.get_movie(to_remove)
if movie:
movies.remove_movie(movie)
movies.display()
![In this lab, you are provided with a MovieNode class, and a partially complete MovieList class.
• A MovieList is a doubly linked list in which each element of the list is a MovieNode
• A MovieNode has the following attributes:
o title: a string, the title of the movie
o year: an integer for the year the movie was first released
o director: a string, the name of the director of the movie
• genre: a string, the genre (or category of the movie) e.g. comedy, drama, action
o next: a reference to the next MovieNode in the list, or None if it is the last in the list
o prev: a reference to the previous MovieNode, or None if it is the first in the list
Task: Complete the method remove_movie (self, movie)
• Input to the method is a MovieObject
• The method removes that MovieObject from the list
You are provided with code in___main___ for testing which prompts the user for a number of movies to remove, finds the MovieNode with
that title in the MovieList. and removes it
For example, if the list contained the following movies, printed using the MovieList method display():
Title:
oint Break
Title: The Power of the Dog
Title: Hunt for the Wilderpeople
Title: Jojo Rabbit
Title: Promising Young Woman
Title: The Piano
removing the movies with the following titles:
Point Break
Jojo Rabbit
would result in the following MovieList
Title: The Power of the Dog
Title: Hunt for the Wilderpeople
Title:
Promising Young Woman
Title: The Piano
Year:
Year: 2021
Year: 2016
Year: 2019
Year: 2020
Year: 1993
Year: 2021
Year: 2016
Year: 2020
Year: 1993
Director: Kathryn Bigelow
Director: Jane Campion
Director: Taika Waititi
Director: Taika Waititi
Director: Emerald Fennell
Director: Jane Campion
Director: Jane Campion
Director: Taika Waititi
Director: Emerald Fennell
Director: Jane Campion
Genre: action
Genre: drama
Genre: comedy
Genre: comedy
Genre: comedy
Genre: drama
Genre: drama
Genre: comedy
Genre: comedy
Genre: drama](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F45d19586-ebc3-4f1a-8702-47e93c6193b1%2F9d566c7d-9ae5-4e36-95cc-9825c692ee16%2Fsqya5og_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)