This is an exemplary video of what's the nuts and bolts of an operator is and is not. Love the explanation and examples. Now if I could see something on 'tree', will be getting closer to Nirvana. Thank you Fred!
Thank you Fred. It was an excellent explanation on the walrus operator. I have experienced the problem what walrus operator is trying to solve. Next time when I face the problem, I now know the solution.
Hi Fred, what are your thoughts about using the walrus operator for sentinel values in functions? This way, we wouldn’t need to introspect the function to get the `Object`. For example, instead of using this: def validate(a=object()): default_a = validate.__defaults__[0] we could do: def validate(a = ( default_a := object())): Do you think this would be bad practice? Maybe it makes the function signature convoluted?
That's really interesting - never thought of using it that way. Honestly, I just use a global like SENTINEL = object() and use that throughout the functions in my module. Your way avoids using a global, but does make the signature confusing for someone who does not understand assignment expressions. I like it though; now I have to decide if I start using that in my code, or stick to the global! 😀
Great video as always! A minor note: I think random.sample() should be used for hand instead of random.choices(), as the second uses replacement. Of course this not the point of the video :-)
This is an exemplary video of what's the nuts and bolts of an operator is and is not. Love the explanation and examples. Now if I could see something on 'tree', will be getting closer to Nirvana. Thank you Fred!
Thanks Patrick, glad you liked the video.
Can you explain a bit more what you mean by "tree" - like data structure trees?
Thank you Fred. It was an excellent explanation on the walrus operator. I have experienced the problem what walrus operator is trying to solve. Next time when I face the problem, I now know the solution.
keep the channel up, it is very valuable
thanks!
Learned something new today, thank you!
thank you!
Hi Fred, what are your thoughts about using the walrus operator for sentinel values in functions?
This way, we wouldn’t need to introspect the function to get the `Object`.
For example, instead of using this:
def validate(a=object()):
default_a = validate.__defaults__[0]
we could do:
def validate(a = ( default_a := object())):
Do you think this would be bad practice?
Maybe it makes the function signature convoluted?
That's really interesting - never thought of using it that way. Honestly, I just use a global like SENTINEL = object() and use that throughout the functions in my module. Your way avoids using a global, but does make the signature confusing for someone who does not understand assignment expressions. I like it though; now I have to decide if I start using that in my code, or stick to the global! 😀
Great video as always! A minor note: I think random.sample() should be used for hand instead of random.choices(), as the second uses replacement. Of course this not the point of the video :-)
You are absolutely right - I should have used sample(), not choices() - thanks for pointing that out!
Please upload case match video sir
coming up real soon!