python 3.x - endless container iterator with backward\forward movement support -


Support for endless forward / backward movement in standaround library containers, such as itertools.cycle? Or how to implement a one-liner for this?

Current code ():

  def __init __ (self, ...): self .__ weapon = [weapon () ("blaster"), weapon ("Laser"), weapon () ("UM")] self .__ weapon = self .__ weapon [0] ... def next_weapon (self): ind = self.__ weapon.index (self .__ weapon ) If the end of the lieutenant; Lane (self .__ weapon) - 1: self .__ weapon = self .__ weapon [IND + 1] others: self .__ weapon = self .__ weapon [0]  

and About the same code

I

<>

I have decided that the list is the best solution to expand.

  class InfList ("list"): "" "infinite container" "def __int___ (auto, * algs, ** quorz): super () .__ init__ (* args, * * Kwargs) self._index = 0 def current (self): return self [self._index] def next (self): self._index = (self._index + 1)% len (self) return itself [self._index] Def defy (self): self._index = (self._index - 1)% len (self) return self [self._nation]  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -