2

私は Python を学んでいますが、ラボの 1 つでは、単語のリストをインポートして辞書として使用し、その単語のリストをインポートされたテキストと比較する必要があります。これは授業用ではありません。独学で学んでいるか、先生に聞いています。比較を行う前に、そのインポートされたテキストを大文字に変換する方法に夢中になっています。

ラボの URL は次のとおりです: http://programarcadegames.com/index.php?chapter=lab_spell_check

以下の投稿/回答といくつかのYouTubeビデオを見てきましたが、これを行う方法がまだわかりません. どんな助けでも大歓迎です。

すべての文字列を含む Python リストを小文字または大文字に変換します

大文字を小文字に変換する方法

これが私がこれまでに持っているコードです:

# Chapter 16 Lab 11

import re

# This function takes in a line of text and returns
# a list of words in the line.
def split_line(line):
    return re.findall('[A-Za-z]+(?:\'[A-Za-z]+)?',line)

dfile = open("dictionary.txt")

dictfile = []
for line in dfile:
    line = line.strip()
    dictfile.append(line)

dfile.close()

print ("--- Linear Search ---")

afile = open("AliceInWonderLand200.txt")

for line in afile:
    words = []
    line = split_line(line)
    words.append(line)
    for word in words:   
        lineNumber = 0
        lineNumber += 1
        if word != (dictfile):
            print ("Line ",(lineNumber)," possible misspelled word: ",(word))

afile.close()
4

1 に答える 1

1

lb が言うように.upper():

dictfile = []
for line in dfile:
    line = line.strip()
    dictfile.append(line.upper()) # <- here.
于 2013-07-05T14:22:37.217 に答える