急行の止まる駅の間の各駅停車の止まる駅の数を求めるプログラムを描こうとしているのですが、
python
1# -*- coding: utf-8 -*- 2def between_express(a,b): 3 c = [] 4 for i in range(len(b)): 5 if i == 0: 6 t = len(a[0:a.index(b[0])-1]) 7 c.append(t) 8 else: 9 t = len(list[a.index(b[i])+1:a.index(b[i])-1]) 10 c.append(t) 11 print(c) 12 13def test(): 14 denentoshi = ["渋谷","池尻大橋",...]#後には田園都市線の駅名 15 exStops = ["渋谷駅","三軒茶屋駅",...]#後には急行の止まる駅名 16 between_express(denentoshisen,expressStops)
python
1 7 c.append(t) 2 8 else: 3----> 9 t = len(list[a.index(b[i])+1:a.index(b[i])-1]) 4 10 c.append(t) 5 11 print(c) 6TypeError: 'type' object is not subscriptable
このようなエラーが出てしまいました。
この原因を教えてください。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。