def perm_generator(lst):
if len(lst) == 1:
yield lst
else:
for i in range(len(lst)):
for perm in perm_generator(lst[:i] + lst[i+1:]):
yield [lst[i]] + perm
This code has been bugging me, since I don't understand how the yield
s connect to each other. My understanding was that yield
acts like a return
, but it stops temporarily until it is called again. How do these yield
s work?