python dictionary add items

body_daily_close = {
    "mappings": {
        "properties": {
            "trade_date": {
                "type": "keyword"
            }
        }
    }
}
properties = body_daily_close.get("mappings").get("properties")


def daily_close_add_tscodes(tscode):
    properties.setdefault(tscode, {"type": "keyword"})
    print(properties)

 

setdefault function adds a single item can be implemented.

Add effects:

image

 

Reference: Python dictionary (Dictionary)

 

 

 

 

 

 

 

 


Guess you like

Origin www.cnblogs.com/betterwgo/p/11563177.html