Can I simplify this "delayed" python generator?
I want the generator to return what I sent to it in the following iteration:
>>>g = delayed_generator()
>>>g.send(None)
>>>g.send('this')
>>>g.send('is')
'this'
>>>g.send('delayed')
'is'
>>>g.send('!')
'delayed'
I came up with a solution that includes three internal variables, and I am wondering if there is an easier way to do this. This is my decision:
def delayed_generator():
y = None
z = None
while True:
x = yield y
y=x
y = yield z
z=y
z = yield x
x=z
+4