Created
November 19, 2021 22:45
-
-
Save AdoHaha/144264cab487fe1a988ab762d6d9f4f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Shifting: | |
"""minimalistic shifting register""" | |
point = 0 | |
def __init__(self,el,how_m): | |
"""el -- first element to add | |
how_m -- length of shifting register | |
""" | |
self.lis = [el for ii in range(how_m)] # we start with multiplying first element | |
self.how_m = how_m | |
def give_elements(self): | |
nn = 0 | |
for el in self.lis[self.point:]: | |
if nn<self.how_m: | |
yield el | |
else: | |
break | |
nn+=1 | |
for el in self.lis[0:self.point]: | |
if nn<self.how_m: | |
yield el | |
else: | |
break | |
nn+=1 | |
def add_element(self,el): | |
self.lis[self.point] = el | |
self.point +=1 | |
self.point = self.point %self.how_m | |
#usage | |
#shif = Shifting(1,21) | |
#for el in range(21): | |
# shif.add_element(el) | |
#print(list(shif.give_elements())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment