比如:仓库存储情况列表a=["0","A","A","B","B","A","0","0","0"],其中"0"表示空位,"A","B"表示位置上货物种类,现需从中取出一件B货物,则应从右侧取出,取完后,仓库存储列表更新为a=["0","A","A","B","A","0","0","0","0"]。
#读取仓库存储情况列表a,代码略
m=len(a)
kind=input("请输入需要取出的货物种类:")
left=0 #left记录从左侧取出此货物时需移动其他物品的次数
right=0 #right记录从右侧取出此货物时需移动其他物品的次数
i=0;j=m-1
t=[0,0] #t表示是否找到此货物
while i<=j and t!=[1,1]:
if :
i=i+1
elif a[i]!=kind:
left+=1
i=i+1
else:
t[0]=1
if a[j]=="0":
j=j-1
elif a[j]!=kind:
j=j-1
else:
t[1]=1
if left>right:
for k in range(j,m-1):
a[k]=a[k+1]
a[m-1]="0"
else:
for k in range():
a[k]=a[k-1]
a[0]="0"
print(a)