3

だから私はpython 2.7で英語のすべての単語をループして、英語の単語のモールス信号バージョンが未知のモールス語句と一致するかどうかを確認するプログラムを書いています。単純に解釈できないのは、文字間にスペースがないからです。これはコードのスニペットです:

def morse_solver(nol,morse,words): 
#nol is the number of letters to cut down search time,morse is the Morse phrase to decode, and words is a string (or can be a list) of all english words.
    lista=_index(words)
    #_index is a procedure that organizes the input in the following way:[nol,[]]
    selection=lista[nol-1][1]
    #selects the words with that nol to loop through
    for word in selection:
        if morse_encode(word)==morse:
            print morse+"="+word

私の質問は次
のとおりです。 英語のすべての単語のリストを見つけて、それを巨大な文字列にコピーするのはちょっと難しいです。では、少し入力するだけで英語辞書のすべての単語にアクセスする方法または Python モジュールはありますか?

そのようなものが存在しない場合、どうすればそのような大きな文字列を処理できますか? (1行だけに)コピーペーストできる場所はありますか?前もって感謝します

4

2 に答える 2

1

enchant という Python 用の辞書ツールがあります。このスレッドをチェックしてください。

Pythonで単語が英単語かどうかを確認するには?

于 2015-07-10T21:31:00.423 に答える
1

モールス符号が聞こえない場合、何が楽しいのですか? これが Python 2.7 で機能しない場合はお知らせください:

from winsound import Beep
from time import sleep

dot = 150 # milliseconds
dash = 300 
freq = 2500 #Hertz
delay = 0.05 #delay between beeps in seconds

def transmit(morseCode):
    for key in morseCode:
        if key == '.':
            Beep(freq,dot)
        elif key == '-':
            Beep(freq,dash)
        else:
            pass #ignore (e.g. new lines)
        sleep(delay)

example = '----. ----.   -... --- - - .-.. .   --- ..-.   -... . . .-.'
#This last is the first line of
#99 Bottles of Beer in Morse Code
#from http://99-bottles-of-beer.net/language-morse-code-406.html

transmit(example)
于 2015-07-10T22:00:19.380 に答える