Answers for "Nested dictionary Python"

1

python counter nested dictionary

import collections
a = collections.defaultdict(collections.Counter)
inf = [('fruit','apple'),('car','truck'),('fruit','banana'),('fruit','banana')]
for category,item in inf:
    a[category][item] = a[category][item] + 1   
#print(a)
#{'fruit': Counter({'banana': 2, 'apple': 1}), 'car': Counter({'truck': 1})})
Posted by: Guest on June-21-2021
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

python get nested dictionary keys

example_dict.get('key1', {}).get('key2')
Posted by: Guest on August-13-2021
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
-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 "Nested dictionary Python"

Python Answers by Framework

Browse Popular Code Answers by Language