I\'m messing around with file lookups in python on a large hard disk. I\'ve been looking at os.walk and glob. I usually use os.walk as I find it much neater and seems to b
Don't waste your time for optimization before measuring/profiling. Focus on making your code simple and easy to maintain.
For example, in your code you precompile RE, which does not give you any speed boost, because re module has internal re._cache
of precompiled REs.
Note, that some optimization done several years prior can make code run slower compared to "non-optimized" code. This applies especially for modern JIT based languages.