Вот мой код:Удаление вещи из списка Python во время цикла для
toBe =[]
#Check if there is any get request
if request.GET.items() != []:
for x in DB:
try:
#This is removing the PMT that is spcific to the name
if request.GET['pmtName'] != "None":
if not request.GET['pmtName'] in x['tags']:
print x['title'], x['tags']
toBe.append(x)
continue
#This is removing the peak stuff
if int(request.GET['peakMin']):
if int(request.GET['peakMin']) < int(x['charge_peak']):
toBe.append(x)
continue
if int(request.GET['peakMax']):
if int(request.GET['peakMax']) > int(x['charge_peak']):
toBe.append(x)
continue
if int(request.GET['widthMin']):
if int(request.GET['widthMin']) < int(x['charge_width']):
toBe.append(x)
continue
if int(request.GET['widthMax']):
if int(request.GET['widthMax']) > int(x['charge_width']):
toBe.append(x)
continue
except:
pass
#TODO: Stupid hack, this needs to be fixed
for x in toBe:
DB.remove(x)
del toBe
По существу я хочу, чтобы удалить элемент, а затем перейти к следующему. Проблема заключается в том, что когда это происходит, это забивает порядок списка и пропускает некоторые. Кто-нибудь знает об этом? Или, может быть, это просто другой способ сделать это?
благодаря