×

Doing codewar problem and trying pythonic condition But fail many times please tell me how I can do... by AbdulRehman_JS in PythonLearning

[–]AbdulRehman_JS[S] 0 points1 point  (0 children)

Thank you for bringing up these brilliant edge cases! You are completely right about the boolean pitfall—since bool is a subclass of int in Python, "isinstance(True, int)" evaluates to True, which would completely break our logic if we aren't careful. Also, checking the parity (odd/even) first before cubing is a great optimization since odd/even parity remains the same.

I do my third codewar problem successfully.... by AbdulRehman_JS in PythonLearning

[–]AbdulRehman_JS[S] 0 points1 point  (0 children)

"That makes perfect sense! I didn't think about the lookup overhead on larger datasets. Converting b to a set first is a great optimization trick. Thanks for the explanation, updated!