这是我的代码,一切正常,除了 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
[]
其他代码工作正常,仅在“高级”代码上如何使列表变为四个单词而不从中删除任何字符串?