python - constraint list to take only integers -
I'm just trying to increase the list type to get an integer I Attachments , < Strong> setitem , but it does not work. Please give any indication please flip side However, it is for example, provided by See examples of examples that use
class linked_list (list): def __init __ (self): self.indx = 0 def next (self): self.indx + = 1 return self.__ GetItem __ (self indx) def last (self, indx): self.indx - = 1 return yourself .__ GetItem __ (self.indx) def __append __ (self, val): if isinstance no (val, integer): Exception increases ('Only integers are accepted') Super (linked_list, self) .__ attached__ (wal) def __getitem __ (self, indx): try: return super (linked_list, self) .__ GetItem __ (indx ) IndexError, excluding e R: StopIteration () def __setitem __ (self, key, val): if does not isinstance, then (Val, integer): exceptions ('only integers accepted' lift) Super (linked_list, self) .__ setitem__ (Key, val)
MutableSequence automatically below all the other list methods based on the five methods.
expansion method
MutableSequence , able to override all
list methods for calls Will not be
__len __ and
__ insert __ for each element once it overrides any display-sensitive methods E by and it may be modified prior to use more efficiently.
MutableSequence remaining method to implement the list methods.
Comments
Post a Comment