def mkfun(expr):
free = list(ordered(expr.free_symbols))
return lambda *x: expr.subs(zip(free,x))
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/81bc6f32-1a44-411b-9c75-3056d8982ad2n%40googlegroups.com.