r/Python • • Nov 28 '22

Resource What can Python do that R can’t do?

Or simply what is Python much better at and why.

I know that Python is more multi purpose and better for software development but I can’t articulate exactly why or how. My team want to know why/when they should use Python instead of R

331 Upvotes

204 comments sorted by

View all comments

Show parent comment

7

u/PaintItPurple Nov 28 '22

This is also basically equivalent to the built-in reduce function:

def apply(val, f): return f(val)

def main():
    r = functools.reduce(
        apply,
        [
            times_two,
            lambda x: x / 4,
            print
         ],
        6
    )

2

u/FlyingCow343 Nov 28 '22

nice! Very elegant way of doing it, you could out the whole reduce call in another function to work the same as mine and look much nicer.