Is there a better way to write this code to modify an object inheriting from `list` in python?

In response to the previous question , I had, I am now wondering if there is a way to make the following code more enjoyable:

class Cycle(list):

    def insertextend(self, index, other, reverse = False):
        """Extend the cycle by inserting an iterable at the given position."""
        index %= len(self)
        if reverse:
            super(Cycle, self).__init__(self[:index] + list(reversed(other)) + self[index:])
        else:
            super(Cycle, self).__init__(self[:index] + other + self[index:])

Any ideas on how I can remove super(Cycle, self).__init__(...)?

+3
source share
1 answer
 def insertextend(self, index, other, reverse = False):
            """Extend the cycle by inserting an iterable at the given position."""
            index %= len(self)
            if reverse: other = reversed(other)
            self[index:index] = other
0
source

All Articles