Question: 5. (20 points) Design patterns. This question is about two closely related design patterns, i.e., The Iterator Pattern and The Generator Pattern. We want to

 5. (20 points) Design patterns. This question is about two closely

5. (20 points) Design patterns. This question is about two closely related design patterns, i.e., The Iterator Pattern and The Generator Pattern. We want to use these patterns to help us get AAAAA tourist attractions, given a list of attractions of all levels in China (i.e., A, AA, AAA, AAAA, and AAAAA). Read the following code carefully, and answer questions. from collections.abc import Iterator, Iterable, Generator class Attractioniterator if self. Index = len (self. attractions): ralse Stopiteration() if self. attractions [self -index ][1]= 'AAAAA' : result = self. self. index t=1 return result while self - attractions [self. Index [1]!= 'AAAAA': if self -index = len(self,attractions): raise Stoplteration class Attractioniterable: def \( \begin{aligned} & =\text { init._(self, ist) } \\ & \text { self -attractions }=1 s t\end{aligned} \) def iter..(self): return Attracti if Page 9 of 12 CONT'D... Introduction to Object-oriented Analysis and Design Fall 2022 print(isinstance(attractions, Generator)) print('Part 1 ) attractions = Attractioniterator(lst) for attraction in attractions: print(attraction) for attraction in attractions: print(attraction) attractions2 = Attractioniterable(lst) for attraction in attractions2: print(attraction) for attraction in attractions2: print(attraction) (a) (2 points) In the above code, we imported three classes, i.e., Iterable, Iterator and Generator. All of them are Abstract Base Class. Answer True or False. (b) (2 points) Complete the definition of property fiveA such that it allows the following usage. Note: You must use the given class method filter to avoid code duplication. (c) (4 points) Complete the initialization method __init__ in class AttractionIterator to make _next_. work. The special method _next_. returns the next AAAAA attraction (if any)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!