word ladder in python

Posted by user365523 on Stack Overflow See other posts from Stack Overflow or by user365523
Published on 2010-06-13T04:36:16Z Indexed on 2010/06/13 4:42 UTC
Read the original article Hit count: 247

Filed under:
|
|

I'm trying to create a word ladder program in python. I'd like to generate words that are similar to a given word. In c++ or java, I would go through each valid index in the original string, and replace it with each letter in the english alphabet, and see if the result is a valid word. for example (pseudocode)

for (int i = 0; i < word.length(); i++) {
  for (every character c in the alphabet) {
    change the letter of word at index i to be c. 
    if the result is a valid word, store it in a list of similar words
  }
}

.

However, this doesn't seem like a very "python" way of doing things. How would I approach this problem in python?

© Stack Overflow or respective owner

Related posts about python

Related posts about word