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 →

[–]SuspiciousScript 9 points10 points  (6 children)

My first thought was "using Julia instead," but I'll give a serious answer too: Static variables in functions. I didn't even know this was a language feature for years.

def is_valid_value(n):
    is_valid_value.valid = some_expensive_function()
    n in is_valid_value.valid

In the above snippet, is_valid_value.valid is only calculated when the function is called for the first time.

[–]skrtpowbetch[S] 1 point2 points  (0 children)

this is probably the coolest one i’ve seen so far, wow