I share real-world lessons from building scalable systems at Jump Trading, Binance, and running mission-critical cloud ops at GovTech and Singapore Air Force. No fluff, just practical takeaways, hard-earned fixes, and deep dives that matter.
a = [1, 2]; b = aa += [3]print(b) # [1, 2, 3] (same object)
+=mutates the same list in-place, equivalent to list.extend().
For mutable objects (e.g. list, dict, set): += changes the object itself.
For immutable objects (e.g. str, tuple, int): += creates a new object, known as a rebind.
Identity vs Equality
a = [1, 2]; b = [1, 2]a == b # Truea is b # False
a is b β checks identity (same memory object).
a == b β checks equality (same content).
Hash Table
Content-Based Hashing
hash((1, 2, 3)) == hash((1, 2, 3)) # True
Immutable objects are hashed by their contents, not by reference.
Dict Construction
{'a': 1} and dict(a=1) produce the same dictionaryβ{'a': 1}.
Dict Keys View
In Python 3, dict.keys() returns a dynamic view (dict_keys) that updates automatically if the dict changes.
In Python 2, it returned a static list.
Dict Access
from collections import defaultdict# Regular dictregular = {}regular.get('missing') # Returns Noneregular['missing'] # Raises KeyError# defaultdictdd = defaultdict(list)dd.get('missing') # Returns None (same as regular dict!)dd['missing'] # Returns [] (the default!) AND creates the key
With defaultdict, using [] access auto-creates missing keys. So you rarely need .get() with defaultdict since it wonβt raise KeyError anyway.
Dict Order
my_list = [3, 1, 2, 1, 3, 4]# dict.fromkeys() creates a dict with keys from the listdict.fromkeys(my_list) # {3: None, 1: None, 2: None, 4: None}# Keys appear in the order they were FIRST seenlist(dict.fromkeys(my_list)) # [3, 1, 2, 4]# Duplicates removed, original order preserved!
When you try to add a duplicate key, the dict just ignores it (doesnβt update position.
First occurrence wins for positioning, converting back to list gives you the keys in order.