In Python 3, I am writing code to make a list of words of length k, where k is a positive integer, in some given alphabet. The alphabet should be a list (for example, [a,b,c,d]).
Here is the code:
def list_len_k_words(alphabet, k):
list = []
if k == 1:
return alphabet
if k >= 2:
for i in alphabet:
for j in list_len_k_words(alphabet,k-1):
list = list.append(i+j)
return list
This throws the error "'NoneType' object has no attribute 'append'". I partially understand what is happening: if I print the values of i+j that the program generates, the last value is always None. This has something to do with the return statement of my code, but I do not see how to fix it.