Skip to content

Instantly share code, notes, and snippets.

@onesuper
Created August 23, 2013 02:07
Show Gist options
  • Select an option

  • Save onesuper/6314849 to your computer and use it in GitHub Desktop.

Select an option

Save onesuper/6314849 to your computer and use it in GitHub Desktop.
import sys
def sub(instr):
i = 0
gput = put()
gput.next()
while True:
c = instr[i]
if c == '.': break
if c.isdigit():
if instr[i+1] == '.':
gput.send(c)
i += 1
else:
n = int(c)
for j in range(n + 1):
gput.send(instr[i+1])
i += 2
else:
gput.send(instr[i])
i += 1
def put():
m = 1
while True:
c = yield
if m % 3:
sys.stdout.write(c)
else:
sys.stdout.write(c)
sys.stdout.write(" ")
m += 1
# the string must be terminated by a period
sub("a2b5e3426fg0zyw3210pq89r.")
print '\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment