Python Nested Dictionary - 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: Python Nested Dictionary (/thread-33340.html) |
Python Nested Dictionary - michaelserra - Apr-17-2021 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: ')) RE: Python Nested Dictionary - Yoriz - Apr-17-2021 credentials = {} username = 'username' passwd = 'qwerty123' email = '[email protected]' credentials[username] = {'password': passwd, 'email': email} print(credentials)
Thx a lot! - michaelserra - Apr-18-2021 It worked, thx! |