#!/usr/bin/env python
import sys
import re
# regular expressions
pattern = re.compile("[a-zA-Z]*",
re.MULTILINE | re.DOTALL | re.IGNORECASE)
# Read pairs as lines of input from STDIN
for line in sys.stdin:
# loop through every word that matches the pattern
for word in pattern.findall(line):
while i < 1:
if len(converted_word) != WINDOW:
# print "word =", word
if a_to_f_pattern.match(word[i]):
.....
else:
.....
i = 0
這裏這條線字符串索引超出範圍 - 指數誤差
if a_to_f_pattern.match(word[i]):
讓我在標題中的錯誤,我想不通爲什麼
以前,我有while i < len(word)
和它的工作但現在因爲我只想檢查每個單詞的第一個字母,它不起作用。
任何線索?
您的模式是否匹配空字符串? – Bahrom
啊不,它從文本文件中讀取單詞。 –
將'print word'添加到您的循環中。 – Bahrom