def count(exprs, query): """ Return a mapper ``{(k, v)}`` where ``k`` is a sub-expression in ``exprs`` matching ``query`` and ``v`` is the number of its occurrences. """ mapper = Counter() for expr in exprs: mapper.update(Counter(search(expr, query, 'all', 'bfs'))) return dict(mapper)
def count(exprs, query): """ Return a mapper ``{(k, v)}`` where ``k`` is a sub-expression in ``exprs`` matching ``query`` and ``v`` is the number of its occurrences. """ mapper = OrderedDict() for expr in exprs: found = search(expr, query, 'all', 'bfs') for i in found: mapper.setdefault(i, 0) mapper[i] += 1 return mapper