-
Notifications
You must be signed in to change notification settings - Fork 0
/
vanish_like.py
29 lines (24 loc) · 932 Bytes
/
vanish_like.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import random
import sys
class Sentence(object):
def __init__(self, s):
s = s.strip()
assert s.endswith(('.', '?'))
self.ender = s[-1]
self.words = s[0:-1].split(' ')
def __str__(self):
words = list(self.words)
words[0] = words[0][0].upper() + words[0][1:]
while words[-1].endswith(('.', ',', '?')):
words[-1] = words[-1][0:-1]
return ' '.join(words) + self.ender
def reduce(self):
del self.words[random.randint(0, len(self.words) - 1)]
if __name__ == '__main__':
sentences = [Sentence(line) for line in sys.stdin]
initial_word_count = sum([len(sentence.words) for sentence in sentences])
assert initial_word_count >= 316, initial_word_count
while sentences:
print ' '.join([str(s) for s in sentences]) + '\n'
random.choice(sentences).reduce()
sentences = [s for s in sentences if s.words]