#walrusoperator — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #walrusoperator, aggregated by home.social.
-
Just wrote the first blog article in 6 years on my personal blog. 🎉
Handling Paginated API Responses with the Walrus Operator
-
Nullish Coalescing vs Walrus Operator: Modern Operator Face-Off
JavaScript ?? operator vs Python := walrus operator. Which language's modern operator is more useful? This comparison is INSANE!
#javascript #python #javascriptvspython #nullishcoalescing #walrusoperator #modernoperators #programmingcomparison #codecomparison #javascripttricks #pythontricks #syntaxcomparison #viralcoding #codingshorts #es2020 #python3.8
-
Encapsulating the atrocity of umask handling with Python's walrus operator:
os.umask(current_umask := os.umask(0))
This isn't clearly *better*, but at least it's clearly shorter. Without `:=`, we'd need two lines:
current_umask = os.umask(0)
os.umask(current_umask)Note: The awkwardness is a necessary consequence of how POSIX handles umask. Also, neither version is threadsafe.
-
would you use the #WalrusOperator?
if test_fit(i, j, s) or test_fit(i, j, s := 1):
fill_grid(i, j, s)or make it a bit longer like this
if test_fit(i, j, s):
fill_grid(i, j, s)
elif test_fit(i, j, 1):
fill_grid(i, j, 1)? #Python