4 ms·
This is a really nice guide. I've been up to my eyes in python dicts over the last few days so already had most of these figured out. setdefault is new to me,
by aidos 14y ago
This is a really nice guide. I've been up to my eyes in python dicts over the last few days so already had most of these figured out.
setdefault is new to me, which is cool. Unfortunately I can only see one place to use it in my code and it would be inefficient [0]. Best stash it away for later use :)
[0] r = re_subs.setdefault(s, re.compile(s))
- andrewcooke 14y agoiirc re caches regexps. so unless you're using many (more than the cache size [edit: 100]), i wouldn't worry (well, and also measuring before optimising...)
- aidos 14y agoI did wonder if that was the case but I couldn't find anything about it. Just discovered re._MAXCACHE which implies it does cache. Tested and in my case the performance is the same. Thanks for the tip (I was posting half hoping someone would have a better solution). That's another 3 lines of code removed :)