hi 各位高手: 愿请各位不吝赐教:
想要实现一个类似于“弹夹”的功能:原集合是number = ('a','b','c','d','e','f'),想要写一个循环语句使得每次 有且仅有一个number中的元素被pop掉,并流到集合now=[]中,而后这些数字被累计到集合done =[]中, 请问这个功能要怎么循环起来。
尝试着写了一个程序,如下:
number = ('a','b','c','d','e','f')
numerL =list(number)
now =[]
nowL=list(now)
done=[]
doneL=list(done)
while len(numerL) > 0:
numerL = numerL.pop()
nowL = numerL.pop(0)
doneL = now.append(numerL)
print("number列:",numerL)
print("now列:",nowL)
print("done列",doneL)
但得到报错:
Traceback (most recent call last):
File "C:/Users/lenovo/PycharmProjects/Test.9.16/tests/have a try.py", line 17, in
nowL = numerL.pop()
AttributeError: 'str' object has no attribute 'pop'
请问该怎样解决