Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
zip_longest solution in Clear category for Swap Nodes by juestr
from itertools import zip_longest
_guard = object()
def swap_nodes(xs):
it = iter(xs)
for a, b in zip_longest(it, it, fillvalue=_guard):
b is not _guard and (yield b)
yield a
Nov. 1, 2019
Comments: