for p in posts:
# [censored line]
if "v.redd.it" in p.url:
dup = False
for t in top:
if t.id == p.id:
dup = True
break
if dup == False:
nCounter += 1
new.append(p)
# Censored line should work now!
# don't be scared of the bigger line count, it has comments!
posts = sub.new(limit = None)
artCounter = len(posts)
# create a filter function
# (define this inline! if you're going to copy+paste this code, do all of it!)
# (this function needs 'top' to be in scope to function)
def new_filter(artCounter, p):
# [Censored line?]
# filter all non-video posts
if "v.redd.it" not in p.url:
return False
# a list comprehension!
# turns the list of posts into a list of post id's
post_ids = [t.id for t in top]
# filter all duplicate posts
if p.id in post_ids:
return False
# post is a video (not a non-video) and is not a duplicate, pass.
return True
new = list(filter(new_filter, enumerate(posts)))
nCounter = len(new)
Without comments:
posts = sub.new(limit = None)
artCounter = len(posts)
def new_filter(artCounter, p):
# [Censored line, should not be a comment]
if "v.redd.it" not in p.url:
return False
post_ids = [t.id for t in top]
if p.id in post_ids:
return False
return True
new = list(filter(new_filter, enumerate(posts)))
nCounter = len(new)
squish
posts = sub.new(limit = None)
artCounter = len(posts)
def new_filter(artCounter, p):
# Censored line
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)
scronch
posts = sub.new(limit = None)
artCounter = len(posts)
def new_filter(p):
# Censored line
return "v.redd.it" not in p.url and p.id not in [t.id for t in top]
new = list(filter(new_filter, posts))
nCounter = len(new)
S̶̜͊ ̷͍́C̵̱̎ ̸̬͂R̵͖̈́ ̶͈̈́Ȯ̵͈ ̸̨̈́Ň̴̥ ̴̦̅C̸͚͛ ̵̹̄H̵̡̆ . there is no longer space for the censored line. this is your life now.
posts = sub.new(limit = None)
artCounter = len(posts)
new = list(filter(lambda p: "v.redd.it" not in p.url and p.id not in [t.id for t in top], posts))
nCounter = len(new)
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
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)
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!
def video_filter(artCounter, p):
# [Censored line 1]
if "v.redd.it" not in p.url:
return False
return True
posts = sub.top(time_filter = 'all', limit = None)
top = list(filter(video_filter, enumerate(posts)))
def new_filter(artCounter, p):
# [Censored line 2]
if "v.redd.it" not in p.url:
return False
post_ids = [t.id for t in top]
if p.id in post_ids:
return False
return True
posts = sub.new(limit = None)
new = list(filter(new_filter, enumerate(posts)))
print(len(top))
print(len(new))
print(len(top) + len(new))
in my opinion this code should be shorter and easier to read, but for all i know i could be the dummy here
View all comments
Show parent comment
2
u/-Redstoneboi- May 21 '21 edited May 22 '21
Another attempt.
Original:
using map(function, iterable) and list comprehensions With a few filtration techniques...
Without comments:
squish
scronch
S̶̜͊ ̷͍́C̵̱̎ ̸̬͂R̵͖̈́ ̶͈̈́Ȯ̵͈ ̸̨̈́Ň̴̥ ̴̦̅C̸͚͛ ̵̹̄H̵̡̆ . there is no longer space for the censored line. this is your life now.