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
Post a Comment