Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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'}}
Comment

Nested dictionary Python

D = {'emp1': {'name': 'Bob', 'job': 'Mgr'},
     'emp2': {'name': 'Kim', 'job': 'Dev'},
     'emp3': {'name': 'Sam', 'job': 'Dev'}}
Comment

Creating a Nested Dictionary

# welcome to softhunt.net
# Creating a Nested Dictionary
Dictionary = {0: 'Softhunt', 1: '.net',
		2:{'i' : 'By', 'ii' : 'Ranjeet', 'iii' : 'Andani'}}
print(Dictionary)
Comment

nested dict

def dict_generator(indict, pre=None):
    pre = pre[:] if pre else []
    if isinstance(indict, dict):
        for key, value in indict.items():
            if isinstance(value, dict):
                for d in dict_generator(value, pre + [key]):
                    yield d
            elif isinstance(value, list) or isinstance(value, tuple):
                for v in value:
                    for d in dict_generator(v, pre + [key]):
                        yield d
            else:
                yield pre + [key, value]
    else:
        yield pre + [indict]
Comment

python create nested dictionary

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

print(people)
Comment

make nested dict from two dict

data = [
    [14, 77766, [2, 2]],
    [15, 77766, [1, 2]],
    [70, 88866, [1, 5]],
    [71, 88866, [2, 5]],
    [72, 88866, [5, 5]],
    [73, 88866, [4, 5]],
    [74, 88866, [3, 5]],
    [79, 99966, [1, 2]],
    [80, 99966, [2, 2]],
]

c = {}
for key, id_, (value, _) in data:
    c.setdefault(id_, {})[key] = value
print(c)
Comment

PREVIOUS NEXT
Code Example
Python :: Python range Incrementing with the range using a positive step 
Python :: LCS Problem Python 
Python :: print python age input 
Python :: how to swap a lowercase character to uppercase in python 
Python :: how to process numerical data machine learning 
Python :: list of class instances in python 
Python :: Use one function for the "ComboboxSelected", to read multiple combobox 
Python :: combination in python without itertools 
Python :: opencv2.3 
Python :: Simple GUI 
Python :: groupby and add aggregated column 
Python :: decoding to str: need a bytes-like object, list found 
Python :: cashier program with class python 
Python :: How to query one to many on same page 
Python :: Python beginner question - trying to understand return statement 
Python :: python QFileDialog select files 
Python :: np sign no 0 
Python :: list foreach pyhton 
Python :: ring Using Self.Attribute and Self.Method 
Python :: python sort dict by sub value 
Python :: if dict json 
Python :: py3 identify file extension 
Python :: python message from byte 
Python :: funtools rougly equivalent to, internal 
Python :: python min date from dictionary 
Python :: how to multiply integer value with float values in python 
Python :: RuntimeError: Please use tf.experimental.tensorrt.Converter in TF 2.0. site:stackoverflow.com 
Python :: python send email with attachment 
Python :: kivy video recorder 
Python :: sqlalchemy date beween 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =