def consuming_length(iterator):
    """
    Return length of an iterator, consuming its contents. O(1) memory.

    >>> consuming_length(range(10))
    10
    """
    cnt = 0
    for _ in iterator:
        cnt += 1
    return cnt