Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with Intro to Computer Science 2 (Python) problem: Complete the definition of the class OddList that is a subclass of list, of which

Need help with Intro to Computer Science 2 (Python) problem:

Complete the definition of the class OddList that is a subclass of list, of which a partial definition can be found in the template file posted to D2L. The class behaves just like an ordinary list except that it only prints the items in the odd-numbered (e.g. 1, 3, 5, ...) indices. To do this you will need to write the OddListIterator class which has two methods:

__init__ that initializes the list to be printed and the first index to be printed appropriately

__next__ that determines and returns the next item in the list, updating the variables of the class as needed

The template file (what is given):

#Subclass of list that iterates over odd indices class OddList(list): def __init__(self): pass

def __iter__(self): pass

class ListIterator: def __init__(self): pass

def __next__(self): pass

The following shows how the OddList class could be used:

image text in transcribed

Python 3.4.1 Shell File Edit Shell Debug Options Windows Help lst 1 2, 3, 4] lst 1 Odd List lst for num in lst 1 print (num) for num in lst print (num) lst2 Odd List cat i dog hermit crab for a in lst2 print (a, end dog lat Odd List C only for word in lst3 print (word) lstA Odd List for n in lstA print (n) Ln: 31 Col: 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

Students also viewed these Databases questions

Question

Were all members comfortable brainstorming in front of each other?

Answered: 1 week ago

Question

5. What information would the team members need?

Answered: 1 week ago