The Mutable Default Trap
The Dangerous Way
def add_waypoint(pt, route=[]):
route.append(pt)
return route
The Safe Way
def add_waypoint(pt, route=None):
if route is None:
route = []
route.append(pt)
Click add_waypoint('Bear'). Python will allocate memory for both functions.