Question
rotate_left(self) Without constructing any new node objects and without returning anything, rotate the list left so that each node moves one position earlier than it
rotate_left(self) Without constructing any new node objects and without returning anything, rotate the list left so that each node moves one position earlier than it was and the original head becomes the new tail. The length of the list should not change. If the list is empty, this method has no effect.
def rotate_left(self):
# rotate the list left one position. Conceptual indices
# should all decrease by one, except for the head, which
# should become the tail. For example, if the list is
# [ 5, 7, 9, -4 ], this method should alter it to
# [ 7, 9, -4, 5 ]. This method should modify the list in
# place and must not return a value.
# TODO replace pass with your implementation.
pass
__str__(self) Return a string representation of the values currently stored in the list. An empty list should appear as [ ] (note the single space). A list with one integer object should appear as [ 5 ] (note the spaces inside the brackets). A list with two integer objects should appear as [ 5, 7 ], and so on. Pay close attention to the format of this string, and remember that strings can be concatenated with the + operator. To convert other objects to strings, use str(other_object). As long as the class for the other object implements the __str__() method, this approach will work.
def __str__(self):
# return a string representation of the list's
# contents. An empty list should appear as [ ].
# A list with one element should appear as [ 5 ].
# A list with two elements should appear as [ 5, 7 ].
# You may assume that the values stored inside of the
# node objects implement the __str__() method, so you
# call str(val_object) on them to get their string
# representations.
# TODO replace pass with your implementation
pass
def __iter__(self):
# initialize a new attribute for walking through your list
# TODO insert your initialization code before the return
# statement. do not modify the return statement.
return self
def __next__(self):
# using the attribute that you initialized in __iter__(),
# fetch the next value and return it. If there are no more
# values to fetch, raise a StopIteration exception.
# TODO replace pass with your implementation
pass
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started