def iter_counts(seq, same=lambda a, b: a == b):
    """
    >>> list(iter_counts(('a', 'a', 'b', 'A', 'a', None, 'c')))
    [('a', 2), ('b', 1), ('A', 1), ('a', 1), (None, 1), ('c', 1)]
    >>> list(iter_counts(('a', 'a', 'b', 'A', 'a', 'c'), same=lambda a, b: a.upper()==b.upper()))
    [('a', 2), ('b', 1), ('A', 2), ('c', 1)]
    """
    it = iter(seq)
    try:
        prev = next(it)
    except StopIteration:
        return
    count = 1
    for el in it:
        if same(prev, el):
            count += 1
        else:
            yield prev, count
            prev = el
            count = 1
    yield prev, count
