Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. def contains(word,tokens):
  2.     for t in range(len(tokens)):
  3.         if tokens[t] in word:
  4.             return True
  5.  
  6. sentence = "Hello mr. smith this is mrs. smith.  How are you today? Great!"
  7. words = sentence.split()
  8. sentences = []
  9. new_sentence = ''
  10. for word in words:
  11.     if not contains(word,['.','?','!']):
  12.         new_sentence += word+' '
  13.         continue
  14.     if word in ['mr.', 'mrs.']:
  15.         new_sentence += word+' '
  16.         continue
  17.     new_sentence += word
  18.     sentences.append(new_sentence)
  19.     new_sentence = ''
  20.  
  21.  
  22.  
  23. for sentence in sentences:
  24.     print(len(sentence))
  25.     print(sentence)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement