使用编程方式的免费单词列表? [英] Free word list for use programmatically?

查看:86
本文介绍了使用编程方式的免费单词列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个朋友正在谈论她喜欢玩的一个单词游戏,您尝试通过一次切换一个字母来尝试将一个单词转换为另一个单词(他们具有相同的字母数),每个迭代产生一个真实的单词



示例:


MOON - > WOLF

GOON

GOOF

GOLF

WOLF


我认为这是一个有趣的小项目,编写一个程序来生成解决方案,并进一步考虑,给出2个词,确定一个解决方案是否存在,以及最优解的迭代次数。



问题是我无法找到免费的单词列表,我可以通过编程方式轻松访问。我也在考虑使用这个作为借口来学习Python,所以如果有人知道有关如何从Python解析和访问它的免费单词列表和指针,这将是巨大的。用于找出如何找到最佳路径的算法我将自己工作。

解决方案

查看这个问题,这本质上是你要找的。

选项:


  1. 在您的普通或花园品种Unix安装中查找/ usr / share / dict /词。

  2. http://www.ibiblio.org/webster/

  3. < a href =http://wordlist.sourceforge.net/ =noreferrer> http://wordlist.sourceforge.net/

  4. http://svnweb.freebsd.org/csrg/share/dict/ (点击修订文件字的标签)

#4 是我的一个用f或者我自己的 Python实验进入文字游戏,它的效果很好。



对于奖励积分,这里有一些让您开始使用您的单词程序:

  import re 
startwith =MOON
endwith =GOLF
cklength = re.compile('。{' + str(len(startwith))+'}(\\\
)?$',re.I)
filename =C:/dict.txt
words = set(x.strip ).upper()for x in open(filename)if x.match(cklength))

然后将会是一组字典中的所有4个字母的单词。你可以从那里做你的逻辑。


A friend of mine was talking about a word game she liked to play where you try to convert one word to another (they have the same number of letters) by switching one letter at a time, where each iteration produces a real word.

Example:

MOON --> WOLF
GOON
GOOF
GOLF
WOLF

I figured it'd be a fun little project to write a program to generate solutions, and taking it further, given 2 words, determine if a solution exists and the number of iterations in optimal solution.

Problem is I'm having trouble finding free word lists that I can easily access programmatically. I'm also thinking about using this as an excuse to learn Python, so it'd be great if anyone knows of free word lists and pointers on how to parse and access it from Python. The algorithm for figuring out how to find an optimal path I'll work on my own.

解决方案

Check out this question and this question, which are essentially what you are looking for.

Options:

  1. Look for /usr/share/dict/words on your common or garden variety Unix install.
  2. http://www.ibiblio.org/webster/
  3. http://wordlist.sourceforge.net/
  4. http://svnweb.freebsd.org/csrg/share/dict/ (click the 'revision' tag of the file 'words')

#4 is the one I used for my own Python experiment into word games, and it worked nicely.

For bonus points, here's something to get you started on your word program:

import re
startwith = "MOON"
endwith = "GOLF"
cklength = re.compile('.{' + str(len(startwith)) + '}(\n)?$', re.I)
filename = "C:/dict.txt"
words = set(x.strip().upper() for x in open(filename) if x.match(cklength))

Words will then be a set of all 4 letter words in the dictionary. You can do your logic from there.

这篇关于使用编程方式的免费单词列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆