Python Forum
Dictionary named after variable value - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Dictionary named after variable value (/thread-4678.html)



Dictionary named after variable value - Alfred - Sep-02-2017

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


RE: Dictionary named after variable value - sparkz_alot - Sep-02-2017

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".