Spent all day on a Markov lyric generator tutorial

This is the tutorial which is very good imo but I am still new to python so I had to google every second line. I will now paste the code with my comments about pretty much every line detailing what I understand that wasn’t really detailed in the tutorial. It wont be runable but could be a usefule resource for someone or at least I prove my knowledge here: https://yuseftechnologies.wordpress.com/2015/07/07/markov-the-messy-commented-code-for-reference/

Other issues I ran into were trying to paste a part of the code into the python shell and getting an error similar to this but in the end after restarting the shell I no longer had that issue. https://mail.python.org/pipermail/idle-dev/2005-June/002356.html this link is to a guy who went into more detail and had a solution which is to turn off the subprocess, but the location he gives of where it should be, the line it should be on, must have been for a different version and I’m glad I didn’t try to find it on my own.

Well it’s nearing the end of the night. I had some success in the end. I can use an order of 1 or 2 consistently but using 4 I get errors often and 5 and above I seem to get errors every time. The error is something about „in getNextCharacter
for letter in model[fragment].keys():
KeyError: ‚hing'“

and the „hing“ at the end could be thing, ething, mething, something, to something, etc depending on how large or small my order is but it seems to have to do with the largest word in the string „somthing“.

Also I wasn’t able to call the script from the desktop or shell or anything, I keep getting an error about the argv going out of scope which I know is because I don’t know how to pass any variables to them so I changed the sys.argv1 and sys.argv2 to just me typing in the numbers.

so semi success!

 Traceback (most recent call last):
>    File "C:\PYTHON24\lib\idlelib\rpc.py", line 233, in asyncqueue
>      self.putmessage((seq, request))
>    File "C:\PYTHON24\lib\idlelib\rpc.py", line 333, in putmessage
>      raise IOError
> IOError 
There was a socket error, or the socket no longer exists.  In other
words, the link to the subprocess failed while the IDLE GUI was trying
to pass the compiled code to the subprocess for execution.

Pythonn Chat Bot & Markov Chain links

http://stackoverflow.com/questions/7633274/extracting-words-from-a-string-removing-punctuation-and-returning-a-list-with-s

http://codereview.stackexchange.com/questions/94232/learning-chat-bot-with-some-problems

https://pythonism.wordpress.com/2013/10/07/how-to-make-a-chatbot-in-python/

http://www.reddit.com/r/hitbox/comments/2uulzd/introducing_pyhitbot_a_python_template_for/

http://rodic.fr/blog/python-chatbot-1/

http://stackoverflow.com/questions/9706769/any-tutorials-for-developing-chatbots

http://stackoverflow.com/questions/9706769/any-tutorials-for-developing-chatbots

http://eflorenzano.com/blog/2008/11/17/writing-markov-chain-irc-bot-twisted-and-python/

http://code.activestate.com/recipes/194364-the-markov-chain-algorithm/

http://agiliq.com/blog/2009/06/generating-pseudo-random-text-with-markov-chains-u/

http://scifi.stackexchange.com/questions/94769/why-did-luke-use-a-synthetic-crystal-in-his-lightsaber-and-what-were-the-implica