我正在编写一个程序来查看一个单词中是否包含三个连续的双字母,例如簿记。
当我尝试运行程序时,我收到错误,TypeError: 'int' object is ubsubscriptable。有什么理由吗?
def find_word(string):
count = 0
for eachLetter in range(len(string)):
if eachLetter[count] == eachLetter[count + 1] and eachLetter[count+ 2] == eachLetter[count + 3] and eachLetter[count+ 4] == eachLetter[count + 5]:
print string
else:
count = count + 1
def main():
try:
fin = open('words.txt') #open the file
except:
print("No file")
for eachLine in fin:
string = eachLine
find_word(string)
if __name__== '__main__':
main()