Day 51/100 of #100DaysOfPythonTips ๐
Most if / elif chains are a code smell.
If your logic looks like this:
โIf A do this, if B do thatโฆโ
You probably need a dispatch table โ not more ifs.
Use a dictionary that maps keys โ functions.
#Python#pythonlearn#100DaysOfCode3
Day 46/100 of #100DaysOfPythonTips ๐
Pythonโs for loop has an else.
The else block runs only if the loop didnโt break.
โIf I never found it, do this.โ
Itโs perfect for search logic โ clean, readable, and almost nobody uses it.๐ง ๐
#Python#pythonlearn#100DaysOfCodeqYY
Day 42/100 of #100DaysOfPythonTips ๐
* set is implemented as a hash table โ average O(1) lookup
* list is a dynamic array โ O(n) linear scan
* If you care about existence, use a set.
* If you care about order or duplicates, use a list.
#Python#pythonlearn#100DaysOfCodeK
Day 38/100 of #100DaysOfPythonTips
๐: Why __name gets mangled to _Class__name
Itโs not for security.
Itโs not real privacy.
Itโs simply to prevent accidental overrides in subclasses.
#Python#pythonlearn#100DaysOfCode2