Answers for "create nested dictionary in python"

2

Nested dictionary Python

IDs = ['emp1','emp2','emp3']

EmpInfo = [{'name': 'Bob', 'job': 'Mgr'},
           {'name': 'Kim', 'job': 'Dev'},
           {'name': 'Sam', 'job': 'Dev'}]

D = dict(zip(IDs, EmpInfo))

print(D)
# Prints {'emp1': {'name': 'Bob', 'job': 'Mgr'},
#         'emp2': {'name': 'Kim', 'job': 'Dev'},
#         'emp3': {'name': 'Sam', 'job': 'Dev'}}
Posted by: Guest on November-08-2020
2

python create nested dictionary

nested_dict = { 'dictA': {'key_1': 'value_1'},
                'dictB': {'key_2': 'value_2'}}
Posted by: Guest on January-03-2020
0

nested dictionary python

people = {1: {'name': 'John', 'age': '27', 'sex': 'Male'},
          2: {'name': 'Marie', 'age': '22', 'sex': 'Female'}}

people[3] = {}

people[3]['name'] = 'Luna'
people[3]['age'] = '24'
people[3]['sex'] = 'Female'
people[3]['married'] = 'No'

print(people[3])

#Output:
# {'name': 'Luna', 'age': '24', 'sex': 'Female', 'married': 'No'}
Posted by: Guest on July-21-2021
0

create nested dictionary in python

family = {
    "member1":{
        "Name":"Ajay",
        "Age":59,
        "Occupation":"Doctor",
        "Relation":"Dad"
        },
    
    "member2":{
        "Name":"Neha",
        "Age":57,
        "Occupation":"Housewife",
        "Relation":"Mom"
        },
    
    "member3":{
        "Name":"Dev",
        "Age":22,
        "Occupation":"Std",
        "Relation":"Son"
        },
    
    "member4":{
        "Name":"Vivek",
        "Age":21,
        "Occupation":"Std",
        "Relation":"Son"
        },
    
    "member5":{
        "Name":"Hana",
        "Age":16,
        "Occupation":"Std",
        "Relation":"Daughter"
        }
    }

print(family)  # Accessing parent dictionary

print("\n\n",family["member1"])  # Accessing child dictionary

print("\n\n",family["member1"]["Occupation"])  # Accessing child dictionary key
Posted by: Guest on October-19-2021
0

create nested dictionary in python

family = { }  # empty nested dictionary
print("\n",family)

family['member1'] = {}  # adding child dictionary
print("\n",family)


family['member1']['name'] = 'Bob'   # Adding elements one at a time
family['member1']['age'] = 21     # Adding elements one at a time

print("\n",family)  # After adding member1 dictionary 


family['member2'] = {'name': 'Cara', 'age': 25}  # Adding whole member2 dictionary

print("\n",family)
Posted by: Guest on October-19-2021
-1

Nested dictionary Python

D = {'emp1': {'name': 'Bob', 'job': 'Mgr'},
     'emp2': {'name': 'Kim', 'job': 'Dev'},
     'emp3': {'name': 'Sam', 'job': 'Dev'}}
Posted by: Guest on November-08-2020

Code answers related to "create nested dictionary in python"

Python Answers by Framework

Browse Popular Code Answers by Language