これが私のコードです。 def Advance(stringlist) 以外はすべて正常に動作します
def printList(stringlist):
print stringlist or []
def add (stringlist, string):
item = [] if string is None else [string]
return item + (stringlist or [])
def current (stringlist):
item =''
return item + stringlist[0]
def advance(stringlist):
item = []
item2 = item + stringlist[1:]
for item in range(5):
return item2
そして、私はこの結果を探しています
>>> myList = None
>>> printList(myList)
[]
>>> for word in ['laundry','homework','cooking','cleaning']:
... myList = add(myList, word)
... printList(myList)
...
[laundry]
[homework, laundry]
[cooking, homework, laundry]
[cleaning, cooking, homework, laundry]
>>> current(myList)
'cleaning'
>>> for i in range(5):
... myList = advance(myList)
... printList(myList)
... print current(myList)
...
[cooking, homework, laundry, cleaning]
cooking
[homework, laundry, cleaning, cooking]
homework
[laundry, cleaning, cooking, homework]
laundry
[cleaning, cooking, homework, laundry]
cleaning
[cooking
しかし、私は得ています
['cooking', 'homework', 'laundry']
cooking
['homework', 'laundry']
homework
['laundry']
laundry
[]
他のコードは正常に動作しますが、「advance」コードでのみ、リストを 4 つの単語にし、そこから文字列を削除しないようにするにはどうすればよいですか?