Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It’s a neat trick, but I feel like this can break in surprising ways. After all, you’re thinking of |fun| as a single thing, but in reality there are a couple calls in there and the precedence of something like 3 % 2 |add| 5 - 2 could be unintuitive.


Same thing happens in pandas when composing conditionals in a selection operation. You need to use `|` instead of `or`, but its precedence is low so you need to add parens:

    df[(df["col1"] == foo) | (df["col2"] == bar)]




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: