I came across the following function:
def load_words():
"""
Returns a list of valid words. Words are strings of lowercase letters.
Depending on the size of the word list, this function may
take a while to finish.
"""
print("Loading word list from file...")
# inFile: file
inFile = open(WORDLIST_FILENAME, 'r')
# line: string
line = inFile.readline() # reads one entire line from a file (as a string)
# wordlist: list of strings
wordlist = line.split()
print(" ", len(wordlist), "words loaded.")
return wordlist
wordlist = load_words()
I don't understand the assignment of the function load_words() to the variable wordlist? When the variable is assigned, the function gets executed.
Is wordlist the function load_words()? Or is it the return of the function load_words()?
wordlist = load_words()is conceptually not different frominFile = open(WORDLIST_FILENAME, 'r')- a function is called and whatever the function returns is assigned to the variable.