以下を使用して、タブ区切りファイルの最初のいくつかの要素を抽出しようとしています。
words = []
name_elements = []
counter = 0
for line in f:
words = line.split()
for element in words:
counter = counter + 1
if words[element].isupper():
name_elements = words[0:counter-1]
print type(counter)
このコードを実行すると、次のエラーが発生します。
TypeError: list indices must be integers, not str
logout
type(counter) を実行すると、整数だと表示されますが。
問題は何ですか?