python - Pop value from if less than x -


i have array of dictionaries

for row in array:         if row['val'] < 11:             array.pop(array.index(row)) 

in trying remove dictionary array if 1 of values below threshold. works, 1 of items in array

my solution right run statement twice, removes value. how should go this?

you shouldn't modify collection you're iterating over. instead, use list comprehension:

array = [row row in array if row['val'] >= 11] 

also, let's clear 1 other thing. python doesn't have native arrays. has lists.


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -