3
针对a previous question我有,我现在有想知道它是做下面的代码的任何方式更好看:有没有更好的方式来编写这段代码来改变从Python中的`list`继承的对象?
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__(...)
?
你只是想避免使用'super'?你希望在这里获得什么? –
每当我想要改变Cycle中的数据时,对我来说,只要调用list的'__init__'就会觉得有点麻烦。我只是想知道我是否正确。 – user3002473
以下内容的用途是什么? 'index%= len(self)' –