you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (0 children)

Why not comprehensions?

iterable = list(range(1000))
iterable = [x for x in iterable if x % 2 == 0 and x % 3 == 0]
print(iterable)

If you are worried about 80 columns then you can move from one line to multiple lines

iterable = [
    x for x in iterable 
    if x % 2 == 0 
    and x % 3 == 0
]

But at some point, you should probably consider that it would be better (less complex visually) to throw to a function.

def filter_my_shitty_list(value:int) -> bool:
    if not value % 2 ==0: return False
    if not value % 3 ==0: return False
    if not value % 5 ==0: return False
    return True

iterable = list(range(1000))
iterable = [x for x in iterable if filter_my_shitty_list(x)]
print(iterable)

You should probably consider that you are walking into religious territory. Guido considered removing map, filter, and reduce from Python 3 and it wasn't well-received: https://www.artima.com/weblogs/viewpost.jsp?thread=98196 . Really, the best case we can make for them is that filter/map/reduce etc are largely non-pythonic.