There are an unlimited number of ways to do that. You could make a script that just does this:
But, I don’t think that’s what you want. You’re looking for a Language Model. Again, there are many ways of doing this, from the fairly simple Bayesian model to a more advanced neural network language model. If you want to build your own, I would recommend checking out TensorFlow‘s tutorial on language models. Otherwise, you could use something that’s a bit more off the shelf, such as NLTK‘s language model (see example here).