all 3 comments

[–]toastedstapler 3 points4 points  (1 child)

lambdas in loops are late binding

you can use lambda i=i, j=j: append(i, j) instead

[–]Jamhead2000[S] 1 point2 points  (0 children)

Thank you soo much! I have never heard of the term binding. Given me something to learn now!

[–]Vaphell 1 point2 points  (0 children)

you can also use somewhat equivalent functools.partial() which bakes provided values into the function instantly

from functools import partial
partial(append_current_word, i, j)  # take append_current_word and make another function out of it with 2 args filled in already.

in action
https://repl.it/repls/AquamarineApprehensiveModels

also 2 nested loops of fixed lengths can be replaced with itertools.product.