Question
Which snippet provides a suitable implementation for _normalize_idx in a list implementation, in order to support both negative and positive indexes? def _normalize_idx(self, idx): ___________________________
Which snippet provides a suitable implementation for _normalize_idx in a list implementation, in order to support both negative and positive indexes?
def _normalize_idx(self, idx):
___________________________
return nidx
(a) nidx += len(self)
(b) nidx = -idx
if nidx < 0:
nidx += len(self)
(c) nidx = idx
if nidx < 0:
nidx += len(self)
(d) nidx = idx
if nidx < 0:
nidx += len(self)
else:
nidx -= len(self)
def __add__(self, other):
"""Implements `self + other_array_list`. Returns a new ArrayList instance that contains the values in this list followed by those of other."""
assert(isinstance(other, ArrayList))
_________________________________
(a) self.extend(other) return self
(b) nlst = ArrayList() nlst.extend(self) nlst.extend(other) return nlst
(c) return self + self.extend(other)
(d) return self + other
Which snippet correctly implements remove_first in an array-backed list, given that the underlying data storage mechanism is a ContrainedList (as provided in the ArrayList assignment)? def remove_first(self):
Removes and returns the first element in the list.
_________________________________
return val
(a) val = self.data.pop(0)
(b) val = self.data[0] del self.data[0]
(c) val = self[0] del self.data[len(self.data)-1]
(d) val = self[0] del self[0]
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