Python Forum
Dictionary named after variable value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionary named after variable value
#1
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
Reply
#2
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".
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  convert a named tuple to a dictionary Skaperen 13 3,563 Mar-31-2022, 07:13 PM
Last Post: Skaperen
  variable as dictionary name? diazepam 4 11,218 Apr-27-2020, 08:11 AM
Last Post: deanhystad
  Variable ComboBox Named Values MC2020 2 2,173 Jan-10-2020, 02:02 PM
Last Post: MC2020
  Reference new dictionary keys with a variable slouw 4 2,913 May-07-2019, 03:30 AM
Last Post: slouw
  Build a multi-variable dictionary birdieman 4 5,030 Jan-06-2017, 04:34 PM
Last Post: birdieman
  calling an object variable in a dictionary sunhear 3 4,307 Dec-30-2016, 05:28 PM
Last Post: sunhear

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020