Suppose I have
def distance2(vector1, vector2): zipped = zip(vector1, vector2) difference2 = [(vector2 - vector1) ** 2 for (vector1, vector2) in zipp
You are describing the basic usage of always_iterable.
>>> from more_itertools.more import always_iterable >>> for val in always_iterable(1): ... print(val) ... 1
This helper is thoroughly battle-tested in OSS.