def walk_list(list_of_g):
    to_idx = 0
for g_current in list_of_g:
    if not subtle_condition(g_current):
        list_of_g[to_idx] = g_current
to_idx += 1
del list_of_g[to_idx:]
Remove items from a list while iterating without using extra memory in Python