News for hackers. Stuff that matters.
Re:Antirez' tiny JSON selector library by magnusmundus on Tuesday November 28, 2023 @05:37AM (#38444399)
> This works all the time and serves all possible cases.

Unless you want the check to be always against the initial length of your iterable, rather than its modified state, you'd have to repeat the `n = len(iterable)` inside the loop, or introduce some syntactic caramel of the walrus kind (though I'm not sure if it would work here).

Re:Antirez' tiny JSON selector library by Mikhail_Edoshin on Tuesday November 28, 2023 @06:12AM (#38444575)
It is actually much simpler: you change 'n' as well:

    while i < n:
      if shouldDelete(iterable[i]):
        del iterable[i]; n -= 1
      else:
        i += 1