Code to generate a dictionary from two lists
zip and itertools.zip_longest do exactly what you are looking for, you only need to choose between the two depending on the lengths of the lists:

def generator(listKeys, listWords):
    if len(listKeys) &gt; len(listWords):
        zipped = zip_longest(listKeys, listWords)
    else:
        zipped = zip(listKeys, listWords)
    return dict(zipped)


This can even be shortened to

def generator(listKeys, listWords):
    my_zip = zip_longest if len(listKeys) &gt; len(listWords) else zip
    return dict(my_zip(listKeys, listWords))


Note that generator is not a good name for this function as the word generator has a particular meaning in Python.