How to make a dictionary and set Key and Set Value from User Input? (Python)

319
April 29, 2017, at 03:12 AM

I hope this isn't a duplicate, I searched and could not find any answers. So I am curious how to make user input set to a key or value. A good example is a registering Username and Password program, You set the Key to Username and the value the password the user that just registered entered to that Username key. Ex: "ExampleName : Example Pass". Other questions said dict{input} but that only makes a key. how can a make a key for one input then make a value for that Key In another input? Thanks. For those who said this was a duplicate, this is different. The other answers to the other don't specify how to set specific inputs to values.

#Example
username_pass = {}
username_register = input("Register your username and create it.")
#Set this to a Key
password_register = input("What password do you want for this username?"
#Set this to the value for that key
Answer 1

create a dictionary

>>> dir_created = {}
>>> username = str(input('Enter username'))
>>> password = str(input('Enter password'))
>>> dir_created[username]=password

most important make a key as a string

Answer 2

Try this:

userDict = {}
userDict[username_register] = password_register
Answer 3

It is simple. After getting the username and password using input(), just do

username_pass[username_register] = password_register
Answer 4

Or, to make this ridiculously easy:

>>> test = { input(): input() }
bob
password
>>> test
{'bob': 'password'}
READ ALSO
I'm stuck with my python csv homework

I'm stuck with my python csv homework

When I run the code the first time it worksWhen I run it a second time, it can't find the csv file until I replace it

192
TextInput values cannot be saved on sqlite

TextInput values cannot be saved on sqlite

I'm new to Python and KivyNow, I am working on an application that uses python and I also use kivy for the interface

282
How to control EOL and leading spaces in Mako?

How to control EOL and leading spaces in Mako?

With the following, I would like to control the EOL:

216