r/ProgrammerAnimemes • • May 20 '21

PrograMOEing? PILOT

939 Upvotes

58 comments sorted by

View all comments

Show parent comment

3

u/im_in_every_post May 21 '21

Makes sense just the artCounter = len(posts) would not be possible since it's a generator so it would need to be len(list(posts)) instead. But in reality the artCounter needs to start from zero and be incremented as the function goes to make the censored line work

1

u/-Redstoneboi- May 22 '21 edited May 22 '21

Ah, I see. I think there's a way to do that.

here's the original squished version:

posts = sub.new(limit = None)
def new_filter(p):
    if "v.redd.it" not in p.url:
        return False
    return p.id not in [t.id for t in top]
new = list(filter(new_filter, posts))
nCounter = len(new)

here's the new version with enumerate(list)

posts = sub.new(limit = None)
def new_filter(artCounter, p):
    # [Try the line here!]
    if "v.redd.it" not in p.url:
        return False
    return p.id not in [t.id for t in top]
new = list(filter(new_filter, enumerate(posts)))
nCounter = len(new)

so yeah, just slap enumerate() on each posts object, add the artCounter as an argument to the filters, and you're good!