有一个JSON数据保存在本地(约2000条数据),程序运行后会去服务器加载一个最近更新的JSON数据列表(30条,但这里可能会含有本地中已经有的数据),怎么样才可以比较高效的更新本地的JSON数据为最新?
认证高级PHP讲师
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.
key-value
O(1)
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}
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.If it is in k-v format, you can convert it to dict first, and then update