AOJ ITP1_9_Bに関してのコードで、
slicingを使って文字列先頭の数文字を最後尾に移動させたいのですが、
word = list(input())
time = int(input())
for k in range(time):
h = int(input())
tmp1 = word[h:]
tmp2 = tmp1.extend(word[:h])
word = tmp2
print(word)
この場合、
TypeError Traceback (most recent call last)
<ipython-input-4-42a708007e58> in <module>()
3 for k in range(time):
4 h = int(input())
----> 5 tmp1 = word[h:]
6 tmp2 = tmp1.extend(word[:h])
7 word = tmp2
TypeError: 'NoneType' object is not subscriptable
とエラーが出てしまいます。
Noneのタイプのobjectは何を指しているのでしょうか。
print(type(word))
としてもきちんと
<class 'list'>
と帰ってきます。
原因が不明なので、どなたか教えていただけると幸いです。
tmp1
はきちんとlist型になっているのですが、tmp2が急にNoneType型になってしまっています。その原因が分かりません。word = input()
で読み込んで、word = word[h:] + word[:h]
とすることも可能です。