Skip to content

Instantly share code, notes, and snippets.

@samredai
Created November 25, 2019 19:59
Show Gist options
  • Save samredai/ae4cd8f3b6557213e74e6df30d560b7b to your computer and use it in GitHub Desktop.
Save samredai/ae4cd8f3b6557213e74e6df30d560b7b to your computer and use it in GitHub Desktop.
Python: Generate a random, and probably incoherent, sentence
import random
# http://www.desiquintans.com/downloads/nounlist/nounlist.txt
nouns = open('nouns.txt').read().split('\n')
# https://raw.githubusercontent.com/janester/mad_libs/master/List%20of%20Proper%20Nouns.txt
proper_nouns = open('propernouns.txt').read().split('\n')
# https://raw.githubusercontent.com/aaronbassett/Pass-phrase/master/verbs.txt
verbs = open('verbs.txt').read().split('\n')
# https://gist.githubusercontent.com/norcal82/4accc0d968444859b408/raw/d295d94608be043a4774087d6cb19caf3a1f27a2/city_names.txt
cities = open('city_names.txt').read().split('\n')
def speak():
"""Generate a random, and probably incoherent, sentence
Example:
>>> speak()
'Saloon peck circle to nominate statuss in Youngstown'
>>> speak()
'Loaf dress dialogue to remain awards in Santa Barbara'
>>> speak()
'Pigpen troubleshoot poverty to deserve mincemeats in College Station'
"""
subject = str.capitalize(random.choice(nouns))
obj = random.choice(nouns).lower() or random.choice(proper_nouns).lower()
while obj.lower() == subject.lower():
obj = random.choice(nouns).lower() or str.capitalize(random.choice(proper_nouns))
infinitive_noun = random.choice(nouns).lower()
while infinitive_noun.lower in (subject.lower(), obj.lower()):
infinitive_noun = random.choice(nouns).lower()
verb = random.choice(verbs)
infinitive = random.choice(verbs)
while verb.lower() == infinitive.lower():
infinitive = random.choice(verbs)
place = random.choice(cities)
return ' '.join([subject, verb, obj,"to",infinitive,infinitive_noun+"s","in",place])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment