Skip to content

Instantly share code, notes, and snippets.

@tvorogme
Last active March 16, 2017 15:47
Show Gist options
  • Save tvorogme/370c565cf1dc99a06817d39e6267a444 to your computer and use it in GitHub Desktop.
Save tvorogme/370c565cf1dc99a06817d39e6267a444 to your computer and use it in GitHub Desktop.
import re
string = input().rstrip().lstrip()
string = string.lower()
string = re.sub("\.{1}\s*", ". ", string)
tmp_string = string
string = string.split(". ")
string = list(filter(lambda x: len(x), string))
if len(string) != tmp_string.count('.'):
print(-1)
else:
string = list(map(lambda x: x.split(" "), string))
for i in range(len(string)):
for k in range(len(string[i])):
string[i][k] = string[i][k]
if k == 0:
string[i][0] = string[i][0][0].upper() + string[i][0][1:]
string = list(map(lambda x: list(filter(lambda y: len(y), x)), string))
tmp = ""
for sentence in string:
for word_id in range(len(sentence)):
if word_id != len(sentence) - 1:
tmp += sentence[word_id].replace(" ", "") + ' '
tmp += sentence[-1].replace(" ", "")
tmp += ". "
tmp = re.sub("(\s)+", " ", tmp)
if re.match("(\s{0}([A-Z]{1}[a-z]{0,}){1}(\s[a-z]{1,}){0,}\.{1}){1,}(\s{1}([A-Z]{1}[a-z]{0,}){1}(\s[a-z]{1,}){0,}\.{1}){0,}", tmp):
print(tmp)
else:
print(-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment