Sorry about the spelling. I meant to write "A function which I find quite 
useful."

def mkfun(expr):
    free = list(ordered(expr.free_symbols))
    return lambda *x: expr.subs(zip(free,x))

:o)

On Sunday, April 17, 2022 at 10:33:37 AM UTC+1 Andre Bolle wrote:

> A function a fund quite useful, so I thought I'd pass it on.
>
> def mkfun(expr):
>     """ Creates a lambda with arguments which are the alphabetically 
> ordered free symbols.
>     E.g.
>     f1 = mkfun(x**2)
>     print(f1(3))
>     f2 = mkfun(x**2 + y**2)
>     print(f2(3,4))
>     f3 = mkfun(x**2 + y**2 + z**2)
>     print(f3(3,4,5))
>     """
>     free = list(ordered(expr.free_symbols))
>     return lambda *x: expr.subs(zip(free,x))

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/650e6666-3398-457f-bca8-9faac7f99aa1n%40googlegroups.com.

Reply via email to