Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

access nested set with array params python

def nested_set(dic, keys, value):
    for key in keys[:-1]:
        dic = dic.setdefault(key, {})
    dic[keys[-1]] = value
    
>>> d = {}
>>> nested_set(d, ['person', 'address', 'city'], 'New York')
>>> d
{'person': {'address': {'city': 'New York'}}}

from : 
https://stackoverflow.com/questions/13687924/setting-a-value-in-a-nested-python-dictionary-given-a-list-of-indices-and-value
Comment

access nested set with array params python


from functools import reduce  # forward compatibility for Python 3
import operator

def getFromDict(dataDict, mapList):
    return reduce(operator.getitem, mapList, dataDict)

Comment

PREVIOUS NEXT
Code Example
Python :: how to maximize pandas output python 
Python :: connect elasticsearch cloud with python terminal 
Python :: k means image classification 
Python :: why static kwyword not in python 
Python :: couchbase python 
Python :: install eric6 python ide ubuntu 20.04 
Python :: python argparse choice 
Python :: how to write a correct python code 
Python :: mass algorithm python 
Python :: django clodinarystorage 
Python :: python censoring pypi 
Python :: how to access cookies in django 
Python :: mute button tkinter 
Python :: Return an RDD created by coalescing all elements within each partition into a list. 
Python :: new listnode(0) meaning 
Python :: Limits the result count to the number specified 
Python :: how to deploy a file size greater than 100mb on pythonanywhere 
Python :: python write request must be str not bytes 
Python :: two input string sum in django 
Python :: how to make commas appear in integers in terminal python 
Python :: jouer à Snake 
Python :: download viper for python ubutunu 
Python :: os get directory from string 
Python :: pysheet 
Python :: python recall a line from a text file 
Python :: py2-pip (no such package) required by world py2-pip 
Python :: input date args python datetime 
Python :: cptac dataset 
Python :: ** (ArgumentError) lists in Phoenix.HTML and templates may only contain integers representing bytes, binaries or other lists, got invalid entry: 
Python :: loess dataframe 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =