def take_at_most(iterable, n):
    """
    Return a list of at most `n` elements of an iterable, or all the elements
    of the iterable if there are less than `n`
    """
    iterator = iter(iterable)
    result = []
    try:
        for _ in range(n):
            result.append(next(iterator))
    except StopIteration:
        pass
    return result
