I'm trying to build a 'skipper' in Python using iterators.
The idea is that given the following:
' '.join([str(i) for i in skippy([1,'a','b','b',2,1,1,1,'c','d','b'])
We get
1 b b 2 1 d b
As output. The rule being everytime we hit an integer x, we skip the following x items in the iterable.
So far I have:
def skippy(it):
p = 0
for x in it:
if type(x) == int:
for x in range(x):
p = next(it)
yield p
And this doesn't work as expected, any ideas on how to fix it?