kimpeek

Untitled

Feb 6th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. source = """This is the input string, example for the markov chain repeater. and this will be the source for what is to come as a result of the program"""
  2.  
  3. def s_format(_string):
  4. table = str.maketrans('','',"""!@#$%^&*()_+-=~`[]{}\\|;:",./<>?""")
  5. return _string.lower().translate(table)
  6.  
  7.  
  8. def make_dict(_string):
  9. word_dict = dict()
  10. words = _string.split()
  11. for i, word in enumerate(words):
  12. try:
  13. word_dict[word] = words[i + 1]
  14. except IndexError:
  15. word_dict[word] = '.'
  16. return word_dict
  17.  
  18.  
  19. def main():
  20. formatted = s_format(source)
  21. wd = make_dict(formatted)
  22. print(wd)
  23.  
  24. main()
Advertisement
Add Comment
Please, Sign In to add comment