加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python字典中添加项

发布时间:2020-12-20 10:38:20 所属栏目:Python 来源:网络整理
导读: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(tsc
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 字典(Dictionary)

?

?

?

?

?

?

?

?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读