from typing import Counter


def count_pileups(bam, contig, start, end):
    """Returns the number of piled-up bases between the given
    start and end positions in the given contig."""
    raw_counts = Counter({x.pos: x.n
                          for x in bam.pileup(contig, start, end)
                          if start <= x.pos <= end})
    return [{"pos": pos, "count": raw_counts[pos]}
            for pos in range(start, end)]