有没有更好的方法来编写此代码来更改从 python 中的“列表”继承的对象



为了回答我之前的问题,我现在想知道有什么方法可以使以下代码看起来更好:

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:])

关于如何删除super(Cycle, self).__init__(...)的任何想法?

 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

最新更新