if len(lastvalues) == len(lists) and lastkey != key:
    minv = min(lastvalues.values())
difference = value - minv
if candidatediff > difference:
    candidate, candidatediff = (minv, value), difference
lastkey = key
try:
    iterable_map[key][0] = next(it)
except StopIteration:
    del iterable_map[key]
return candidate
наименьший диапазон python из нескольких списков