pulling a dictionary out of the function that created it (python)
Question: I am importing a list from an outside document, and inputing that list into a
dictionary. This question is applicable to pretty much all values associated
to a variable from inside a function. Once the function is complete how do I
pull that information from the function with out having to assign the
variables as global. Sorry if this question isnt very clear, im having trouble
vocalizing it.

Here is the program so far. the dictionary 'result' has values while in the
function but when I try to call it from outside the function its empty.

    
    
    fin = open('words.txt')
    
    def dictionary(words):
       result = {}
       for line in words:
          result[line] = 'yupp!' # dont care about value at the moment
       return result
    
    word_dict = dictionary(fin)
    'the' in word_dict# checking to see if a word is in the dictionary
    


Answer: Use:

    
    
    result = dictionary(fin)
    

to assign the value returned by `dictionary` to the variable `result`.

Note that `result` is a global variable, so I'm not sure what you mean by
"with out having to assign the variables as global".

* * *
    
    
    def dictionary(words):
        result = {}
        for word in words:
            word = word.strip()
            result[word] = 'yupp!'
        return result
    
    with open('words.txt') as fin:
        result = dictionary(fin)
        print('the' in result)
    

* * *

Alternatively,

    
    
    def dictionary(words):
        return dict.fromkeys((word.strip() for word in words), 'yupp')
    

