4 ms·
If missing variables are an issue you could use defaultdict. http://docs.python.org/lib/defaultdict-objects.html http://docs.python.org/lib/defaultdict-objects
by bayareaguy 19y ago
If missing variables are an issue you could use defaultdict.
http://docs.python.org/lib/defaultdict-objects.html http://docs.python.org/lib/defaultdict-objects.html
- connellybarnes 19y agoGood point, and thanks for pointing out defaultdict(); I wasn't even aware of that class. I suppose one could use defaultdict() to gain associativity also (pass 'not found' variables through unmodified). I think I still slightly prefer replace(), for uninteresting reasons.