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 函数可以实现单个项的添加。

添加效果:

python字典中添加项

 

参考:Python 字典(Dictionary)

 

 

 

 

 

 

 

 

python字典中添加项


相关文章:

  • 2021-07-05
  • 2022-12-23
  • 2022-01-18
  • 2022-12-23
  • 2022-03-09
  • 2022-12-23
  • 2022-12-23
  • 2021-05-13
猜你喜欢
  • 2022-12-23
  • 2022-03-07
  • 2022-01-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案