0

I'm new in Python and I wonder if there is a way to use the last execution in the same code line. In R you can do that with pipes (%>%).

For example:

In R you can do this:

list(filter(lambda x: '_LI' not in x,BI.columns))) %>% list(filter(lambda x: '_LS' not in x,.)

that is the same as:

list(filter(lambda x: '_LS' not in x,list(filter(lambda x: '_LI' not in x,BI.columns))))

That last one works fine in Python but I like more the first way and I want to do the same in Python. Is it possible?

  • 1
    No, Python doesn't have anything like this unfortunately. I believe there's libraries that *slightly* emulate it by using bitwise operators and wrapper classes, but they aren't great. – Carcigenicate Aug 31 '20 at 21:55
  • Maybe `list(filter(lambda x: '_LI' not in x,BI.columns)); list(filter(lambda x: '_LS' not in x,_))`? – superb rain Aug 31 '20 at 21:58
  • @superbrain Although that only works in a REPL. – Carcigenicate Aug 31 '20 at 21:59
  • @Carcigenicate That's actually half the reason I said "maybe" :-) The other half being that my REPL shows both lists and I'm not sure that's desired. Both issues can of course be overcome by explicitly assigning the first result to a variable. Not sure why they're not just doing that. – superb rain Aug 31 '20 at 22:05
  • https://stackoverflow.com/questions/28252585/functional-pipes-in-python-like-from-rs-magritrr may be helpful - the answers have some packages that do similar things in Python. – bouteillebleu Aug 31 '20 at 22:30

0 Answers0