Skip to content

Instantly share code, notes, and snippets.

@kshcherban
Last active January 22, 2017 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kshcherban/730d216bb2d0a434ba0e0c9c9587554b to your computer and use it in GitHub Desktop.
Save kshcherban/730d216bb2d0a434ba0e0c9c9587554b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import string
def join_punctuation(seq):
characters = set(string.punctuation)
seq = iter(seq)
current = next(seq)
for nxt in seq:
if nxt in characters:
current += nxt
else:
yield current
current = nxt
yield current
def main():
new_line = []
for word in line.split():
if word in string.punctuation:
new_line.append(word)
elif word in to_translate:
new_line.append(translate(word))
else:
new_line.append(translit(word))
return ' '.join(join_punctuation(new_line))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment