def args_to_iterable(*args, **kwargs): """ Convert arguments to iterables. Parameters ---------- args: iterables or not arguments n : int, optional number of explicit arguments """ if 'n' in kwargs: n = kwargs['n'] else: n = len(args) arguments = [] for i, arg in enumerate(args): arguments.append(ensure_iterable(arg)) it = iter(arguments) for _ in range(n): yield next(it, None) if n < len(args): yield tuple(it)
def test_ensure_iterable(): el = 1 new_el = ensure_iterable(el) assert new_el == [el]
def test_ensure_iterable_string(): el = 'test' new_el = ensure_iterable(el) assert new_el == [el]