Last active
January 22, 2017 15:10
-
-
Save kshcherban/730d216bb2d0a434ba0e0c9c9587554b 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
#!/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