samedi 17 janvier 2015

How do I generate a random text from random words

I wanna generate a random text with words i get from another text.

I was also supposed to do it with random letters, it looks like this:



def write_random_text_with_letters(self, amount):
return re.sub(ur'[^a-zA-Z,. ]', '', u''.join([random.choice(list(self.text)) for i in range(amount)]))


But how to I do write it from this:



def picked_words_from_text(self):
return filter(unicode.isalpha, list(self.text.split()))


I also have a probability over the words, and I need to write the new text from this words and pick it from the words with most probability.

Hope u can help me guys.





Aucun commentaire:

Enregistrer un commentaire