Home  >  Q&A  >  body text

Python中如何通过一个JSON中个数据更新另外一个JSON?

有一个JSON数据保存在本地(约2000条数据),程序运行后会去服务器加载一个最近更新的JSON数据列表(30条,但这里可能会含有本地中已经有的数据),怎么样才可以比较高效的更新本地的JSON数据为最新?

PHP中文网PHP中文网2741 days ago228

reply all(2)I'll reply

  • 阿神

    阿神2017-04-17 17:34:04

    Because I don’t know the form of your data, I can only say - list storage is a linear time update, saving space and time: If it is a dictionary key-value的形式是O(1)complexity update. Trade space for time.

    reply
    0
  • 迷茫

    迷茫2017-04-17 17:34:04

    If it is in k-v format, you can convert it to dict first, and then update

    old = {"a":1,"b":2}
    new = {"a":2,"c":3}
    old.update(new)
    # old={"a":2,"b":2,"c":3}

    reply
    0
  • Cancelreply