Julien Palard on Nostr: npub1kg5kt…vtnac npub1kpwlx…xxzz4 In Python they are functions, not methods, ...
npub1kg5ktxlealkymv59ghper5klmc8n5vqppclxytkqg9jzk0wkmwhqzvtnac (npub1kg5…tnac) npub1kpwlxpzkxfmuxjmzc2wp3rf9vjg0sgydmlhsnrgqr3maf59h86qqdxxzz4 (npub1kpw…xzz4) In Python they are functions, not methods, because they work with any iterable (strings, lists, tuples, bytes, literraly any containers, even the ones you create). It's easier than having to implement a map and a reduce method on every container.
But in Python we don't even use map and filter, comprehensions are (very often) more readable:
>>> sum(map(abs, filter(lambda x: x > 10, the_iterable)))
vs
>>> sum(abs(x) for x in the_iterable if x > 10)
But in Python we don't even use map and filter, comprehensions are (very often) more readable:
>>> sum(map(abs, filter(lambda x: x > 10, the_iterable)))
vs
>>> sum(abs(x) for x in the_iterable if x > 10)