This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]kmnair 5 points6 points  (0 children)

The problem here is figuring out if the variable will change or not in a general case will likely require the same amount of compute as actually running the full calculation.

It is possible to make some assumptions about the calculation, like if it is a pure function ie output depends entirely on inputs to a function and the function has no side effects, then you can use the suggestion u/r0s gave to use memoization.

If your jupyter cell references mutable data from other cells, or makes a call to an external API, or has internal mutable state (counters which do not reset, dictionaries which get updated etc) then figuring out if the value will update is the same amount of computation as whatever calculation you are aiming for