Python Forum

Full Version: Dictionary named after variable value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am really new to Python and coding overall. I just have one question, I am trying to create a dictionarie based on a variable. I want to name the dictionarie based on the value of the variable. What ends up happening is that the dictionarie is called username(the name of the varible)insted of the value of the varible. Does anyone know how to do this? If so, please tell me.

username = input("username:")
username = {}

/Alfred
Well, once you get the users name and assign it to 'username', you overwrite (delete) it as soon as you create the dictionary, making the variable useless. A better way is to name your dictionary something like "username_dict".