def sized_imap(func, iterable, strict=False):
    '''
    Return an iterable whose elements are the result of applying the callable `func`
    to each element of `iterable`. If `iterable` has a `len()`, then the iterable returned
    by this function will have the same `len()`. Otherwise calling `len()` on the
    returned iterable will raise `TypeError`.

    :param func: The function to apply to each element of `iterable`.
    :param iterable: An iterable whose objects will be mapped.
    :param bool strict: If `True` and `iterable` does not support `len()`, raise an exception
        immediately instead of returning an iterable that does not support `len()`.
    '''
    try:
        length = len(iterable)
    except TypeError:
        if strict:
            raise
        else:
            return imap(func, iterable)
    return SizedGenerator(lambda: imap(func, iterable), length=length)
Return an iterable whose elements are the result of applying the callable `func`
    to each element of `iterable`. If `iterable` has a `len()`, then the iterable returned
    by this function will have the same `len()`. Otherwise calling `len()` on the
    returned iterable will raise `TypeError`.

    :param func: The function to apply to each element of `iterable`.
    :param iterable: An iterable whose objects will be mapped.
    :param bool strict: If `True` and `iterable` does not support `len()`, raise an exception
        immediately instead of returning an iterable that does not support `len()`.