Author terry.reedy
Recipients eric.smith, paul.moore, sreedevi.ha, steven.daprano, terry.reedy
Date 2020-09-24.20:02:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1600977732.31.0.809523173572.issue41774@roundup.psfhosted.org>
In-reply-to
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>
2020-09-24 20:02:12terry.reedylinkissue41774 messages
2020-09-24 20:02:12terry.reedycreate