Python Forum

Full Version: Python Nested Dictionary
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to create a little program that stores user-entered information in a nested dictionary and then converts it to a Pandas dataframe.

The dictionary should look something like this:
Credentials = { 'username' : {'password' : 'qwerty123'
'email' : '[email protected]'}
}
I don't know how to store the credentials in the appropriate dictionary assigned to the username entered. I tried several solutions but they didn't work. Here is the code:
import pandas as pd
while True:
    print('Welcome to profiles creator!')
    CreateDict = str(input('Do you want to create a new profile? (y/n): '))
    if CreateDict == 'y' or CreateDict == 'yes':
        Dict = dict()
    elif CreateDict == 'n' or CreateDict == 'no':
        break;
    else:
        print('Insert valid character!')
    Username = str(input('Username: '))
    Passwd = str(input('New password: '))
    BirthDate = str(input('Date of birth (MM/GG/YY): '))
    Notes = str(input('Addition optional info: '))
   
credentials = {}

username = 'username'
passwd = 'qwerty123'
email = '[email protected]'

credentials[username] = {'password': passwd, 'email': email}

print(credentials)
Output:
{'username': {'password': 'qwerty123', 'email': '[email protected]'}}
It worked, thx!