Find words in string

So, ive made a really simple monkey on a typewriter program that randomly spams letters, now i want to find any real words in the random jumble of letters and only print the words, instead of random letters, what ive got so far is this that spams letters.

import random
import time
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
x = 1
while x == 1:
  rnd = random.randint(0,25)
  print(alphabet[rnd], end = "", flush = True)
  rnd = 0.05
  time.sleep(rnd)

I need to make it spam the letters, but not print them, then check for words in the random letters, then print those words.
Any help is appreciated :slight_smile:

This sounds like homework.

Having written a thing for this, the answer is that one consults a dictionary.

You can either use a program/API that talks to a dictionary (there are a number), or you can check the dictionary by hand.

Your computer may come with a dictionary / API for checking it, or you may download one.

For my project, https://check-spelling.dev, I download one and check it by hand.

For putting letters somewhere you can work with instead of dumping them, check io.StringIO.

The random module has a nice function to choose a random element from a sequence, instead of messing with the index. And the sleep only makes your program slow, limit the output size instead.