I have problems understanding how this generator works. How exactly does it create permutations? Also, in the code, what does yield[items[i]] + cc
yield and to where? What is added to the list yield[]
each time yield[items[i]] + cc
is called? (is anything even added?) i'm sorry but I'm really confused:(
sorry for such a novice question and I hope someone could help me understand this better! Thanks!
def permutations(items):
n = len
if n == 0:
yield[]
else:
for i in range(len(items)):
for cc in permutations(items[:i] + items[i+1:]:
yield[items[i]] + cc
for p in permutations(['r','e','d']):
print ''.join(p)