import sys
list = []
list.append("0") # 0 means unavailable
list.append("2")
list.append("3")
list.append("0")
list.append("4")
list.append("5")
list.append("0")
def remove(del_value):
list.remove(del_value)
return list
# 取可用的值
def get_value():
global available
if 0 == (len(list)): # 列表是否是空
print("List empty,no available!")
sys.exit(-1)
for i in range(len(list)):
if list[i] == "0": # 是否可用,不可用就删除
remove(list[i])
get_value()
else:
available = list[i] # 取值
return available
if __name__ == '__main__':
print("available: " + str(get_value()))
print("available: " + str(get_value()))
print("available: " + str(get_value()))
print("available: " + str(get_value()))
print("available: " + str(get_value()))
print("available: " + str(get_value()))
python列表元素的动态删除和取值
最新推荐文章于 2024-07-16 19:26:54 发布