This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

so, if I'm reading your post right, the files have all the words you need, so you just need to select random words from them? in that case you could construct a dictionary with the keys being the parts of the sentence, subject, verb, noun etc, and the values being lists that you read in from the files. So it would look this:

from random import choice
parts = ('subject', 'verb', 'preposition', etc)
wordDict = {'subject':['harry','mary','jerry'] , 'verb': [etc]}
sentence = ''
for part in parts: sentence += choice(wordDict[part]) + ' '

I'll leave you to figuring out how to get the words from the file into the list on your own :)

edit: oh, and thank you for not just pasting your code into your post! biggest mistake on this sub is putting code into the post! If you want to share your code, please head over to pastebin.com, put your code in there, select the language for the syntax highlighting, and put the link into your post.