def wordsgenerator_uptoK(alphabet, length):
    """
       Generate all the permutations of 
       the chars of the string length length 
       and output them into a list
       -----------------------------------------
        Parameters:
            alphabet (str)
            length (int)
        
        eg.
        wordsgenerator_uptoK("AB",2)
        
        output:
        ['AA', 'AB', 'BA', 'BB']
                 
            """
    c = [[]]
    for i in range(length):
        c = [ [x]+y     for x in alphabet      for y in c]
        
    wordsofsize=list()
    for w in c:
        wordsofsize.append(''.join(w))
    return wordsofsize