Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Nested Dictionary
#1
Lightbulb 
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: '))
   
Reply
#2
credentials = {}

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

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

print(credentials)
Output:
{'username': {'password': 'qwerty123', 'email': '[email protected]'}}
michaelserra likes this post
Reply
#3
It worked, thx!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  need to compare 2 values in a nested dictionary jss 2 847 Nov-30-2023, 03:17 PM
Last Post: Pedroski55
  Nested dictionary acting strange Pedroski55 2 2,076 May-13-2021, 10:37 PM
Last Post: Pedroski55
  format the output from a nested dictionary. nostradamus64 9 4,514 May-03-2021, 04:45 PM
Last Post: nostradamus64
  nested dictionary rkpython 7 3,249 May-29-2020, 11:13 AM
Last Post: rkpython
  Nested Dictionary/List tonybrown3 5 3,139 May-08-2020, 01:27 AM
Last Post: tonybrown3
  Help: for loop with dictionary and nested lists mart79 1 1,859 Apr-12-2020, 02:52 PM
Last Post: TomToad
  Transforming nested key-tuples into their dictionary values ClassicalSoul 4 2,656 Apr-11-2020, 04:36 PM
Last Post: bowlofred
  How to change value in a nested dictionary? nzcan 2 5,762 Sep-23-2019, 04:09 PM
Last Post: nzcan
  Transform simplified dictionary to nested dictionaries bhojendra 1 2,362 Jul-02-2019, 02:05 PM
Last Post: ichabod801
  Convert List of Dictionary to dictionary of dictionary list in python kk230689 2 49,740 Apr-27-2019, 03:13 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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