Skip to content

Instantly share code, notes, and snippets.

@menicosia
Created December 13, 2020 03:42
Show Gist options
  • Save menicosia/3e28abf3ed20e522a6d497da1b1a6d44 to your computer and use it in GitHub Desktop.
Save menicosia/3e28abf3ed20e522a6d497da1b1a6d44 to your computer and use it in GitHub Desktop.
Finding a random word using Python
>>> import re
>>> import random
>>> import time
>>> random.seed(time.time())
>>> wordHandle = open("/usr/share/dict/web2")
>>> words = wordHandle.readlines()
>>> aFilter = re.compile("^[Aa]")
>>> wordsWithA = list(filter(aFilter.match, words))
>>> len(wordsWithA)
17096
>>> random.choice(wordsWithA).strip()
'apophorometer'
>>> random.choice(wordsWithA).strip()
'auricular'
>>> random.choice(wordsWithA).strip()
'aerodrome'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment