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
Is there a better way to write this code to alter an object inheriting from `list` in python?
-
12-10-2022 - |
Pregunta
In response to a previous question I had, I am now wondering it there is any way of making the following code look nicer:
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 as to how I can remove the super(Cycle, self).__init__(...)
?
Solución
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow