列出以< user input>开头的字典中的所有单词。 [英] List all words in a dictionary that start with <user input>
本文介绍了列出以< user input>开头的字典中的所有单词。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在用户输入字符串的程序中执行程序,程序会生成以该字符串开头的单词列表?
How would a go about making a program where the user enters a string, and the program generates a list of words beginning with that string?
Ex:
用户:abd
程序:abdicate,abdomen,abduct ...
Ex:
User: "abd"
Program:abdicate, abdomen, abduct...
谢谢!
编辑:我使用python,但我认为这是一个相当语言无关的问题。
I'm using python, but I assume that this is a fairly language-independent problem.
推荐答案
如果您在debian [-like]机器上,
If you on a debian[-like] machine,
#!/bin/bash
echo -n "Enter a word: "
read input
grep "^$input" /usr/share/dict/words
在我的P200上使用0.040秒。
Takes all of 0.040s on my P200.
这篇关于列出以< user input>开头的字典中的所有单词。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文