4 ms·
Keep in mind I have no idea how this magical code works. In fact I can't even find the pipe character on my keyboard right now (I am copy and pasting it!). But
by heyitsnick 16y ago
Keep in mind I have no idea how this magical code works. In fact I can't even find the pipe character on my keyboard right now (I am copy and pasting it!). But this seems to work:
@Pipe
def p(iterable, function, **kwargs):
return function(iterable, **kwargs)
In [3]: from pipe import *
In [4]: [1,2,3,4,5] | p(sum)
Out[4]: 15
- yesbabyyes 16y agoOr even just wrap the function in Pipe: >>> from pipe import * >>> [1, 2, 3, 4, 5] | Pipe(sum) 15
- jerf 16y ago"In fact I can't even find the pipe character on my keyboard right now" On standard US keyboards, it's shift-backslash. YLMV.
- lloeki 16y agoOn Mac keyboards it's alt+shift+L. Just in case.
- heyitsnick 16y agoHa thank you! I was typing the pipe character that's in the top left (alt gr + `) that looked the same but is clearly a different character code. It's a bew laptop with a new keyboard layout (US).