Need help python   " Write an Array Data Structure which has a constructor, "len", "str", "itr", "getitem" and "setitem" methods.   Then create an object of this Array class with 6 elements in it. Fill the object of this class with numbers from 3 to 8.   print the array and show the length of the array object."   Here is the array code """ File: arrays.py An Array is a restricted list whose clients can use only [], len, iter, and str. To instantiate, use = array(, ) The fill value is None by default. """ class Array(object):     """Represents an array."""     def __init__(self, capacity, fillValue = None):         """Capacity is the static size of the array.         fillValue is placed at each position."""         self.items = list()         for count in range(capacity):             self.items.append(fillValue)     def __len__(self):         """-> The capacity of the array."""         return len(self.items)     def __str__(self):         """-> The string representation of the array."""         return str(self.items)     def __iter__(self):         """Supports traversal with a for loop."""         return iter(self.items)     def __getitem__(self, index):         """Subscript operator for access at index."""         return self.items[index]     def __setitem__(self, index, newItem):         """Subscript operator for replacement at index."""         self.items[index] = newItem

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 9RQ
icon
Related questions
Question

Need help python

 

"

Write an Array Data Structure which has a constructor, "len", "str", "itr", "getitem" and "setitem" methods.

 

Then create an object of this Array class with 6 elements in it. Fill the object of this class with numbers from 3 to 8.

 

print the array and show the length of the array object."

 

Here is the array code

"""
File: arrays.py

An Array is a restricted list whose clients can use
only [], len, iter, and str.

To instantiate, use

<variable> = array(<capacity>, <optional fill value>)

The fill value is None by default.
"""

class Array(object):
    """Represents an array."""

    def __init__(self, capacity, fillValue = None):
        """Capacity is the static size of the array.
        fillValue is placed at each position."""
        self.items = list()
        for count in range(capacity):
            self.items.append(fillValue)

    def __len__(self):
        """-> The capacity of the array."""
        return len(self.items)

    def __str__(self):
        """-> The string representation of the array."""
        return str(self.items)

    def __iter__(self):
        """Supports traversal with a for loop."""
        return iter(self.items)

    def __getitem__(self, index):
        """Subscript operator for access at index."""
        return self.items[index]

    def __setitem__(self, index, newItem):
        """Subscript operator for replacement at index."""
        self.items[index] = newItem

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT