Calling a function, stored as a value in a dictionary, if the user's input matches the value's key
<p>I'm currently creating a simple interactive fiction (IF) game in Python. In addition to the commands relevant to each room they explore, I would like for the player to have access to a list of "global commands" that can be called at anytime (inventory, help, etc).</p>

<p>I used <a href="https://stackoverflow.com/questions/5134482/python-call-function-from-user-input">this</a> thread to get started, but I don't think it's quite what I'm looking for. </p>

<p>Essentially, what I want is something like this (obviously, not all of this is valid code):</p>

<pre><code>def inventory():
    # Shows the user's inventory

def game_help():
    # shows a list of available commands

global_commands = {
    'inventory': inventory(),
    'help': game_help(),
}

command = raw_input().downcase()
if command == "get item":
     print "You take the item"
elif command == "open door":
     print "You open the door"
elif command in global_commands:
     # execute the function that is tied to the user's input
</code></pre>

<p>Any and all help is appreciated!</p>