Filtering os.walk() dirs and files

This solution uses fnmatch.translate to convert glob patterns to regular expressions (it assumes the includes only is used for files): import fnmatch import os import os.path import re includes = [‘*.doc’, ‘*.odt’] # for files only excludes = [‘/home/paulo-freitas/Documents’] # for dirs and files # transform glob patterns to regular expressions includes = r’|’.join([fnmatch.translate(x) for … Read more

Compare two 2D arrays & get intersection and differences

Convert arrays to a format, where array index is the sight_id: $b1 =array(); foreach($a1 as $x) $b1[$x[‘sight_id’]] = $x[‘location’]; $b2 =array(); foreach($a2 as $x) $b2[$x[‘sight_id’]] = $x[‘location’]; Calculate the differences and intersection: $c_intersect = array_intersect_key($b1,$b2); $c_1 = array_diff_key($b1,$b2); $c_2 = array_diff_key($b2,$b1); Convert arrays back to your format: $intersect_array = array(); foreach($c_intersect as $i=>$v) $intersect_array[] = … Read more