This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy eric.smith, paul.moore, sreedevi.ha, steven.daprano, terry.reedy 2020-09-24.20:02:12 -1.0 Yes <1600977732.31.0.809523173572.issue41774@roundup.psfhosted.org>
Content
```I modeled the new entry on the previous one.  The code and its test.

def fr(n, remove):
mylist = list(range(n))
for i in range(len(mylist)-1, -1, -1):
if remove(mylist[i]):
del mylist[i]
return mylist

def ff(n, keep):
mylist = list(range(n))
j = 0
for i, item in enumerate(mylist):
if keep(item):
mylist[j] = item
j += 1
del mylist[j:]
return mylist

for i in range(9):

expect = list(range(0, i, 2))
def remove(n): return n % 2
def keep(n): return n % 2 == 0
print(fr(i, remove) == ff(i, keep) == expect)

expect = list(range(i//2))
def remove(n): return n >= i//2
def keep(n): return n < i//2
print(fr(i, remove) == ff(i, keep) == expect)

expect = list(range(i//2, i))
def remove(n): return n < i//2
def keep(n): return n >= i//2
print(fr(i, remove) == ff(i, keep) == expect)

# all True```
History
Date User Action Args
2020-09-24 20:02:12terry.reedysetrecipients: + terry.reedy, paul.moore, eric.smith, steven.daprano, sreedevi.ha
2020-09-24 20:02:12terry.reedysetmessageid: <1600977732.31.0.809523173572.issue41774@roundup.psfhosted.org>