想使list = {"items":{"a":1,"b":2},{"a":7,"b":4},{"a":9,"b":12}}
应如何操作?
7 个解决方案
#1
不要使用初始化
#2
你就不能存个list当key吗?
#3
list = {}
list['items'] = [{"a":1,"b":2},{"a":7,"b":4},{"a":9,"b":12}]
这个意思?
#4
可以这样
list = {"items":[{"a":1,"b":2},{"a":7,"b":4},{"a":9,"b":12}]}
取值 list["items"][0]["a"]
list = {"items":[{"a":1,"b":2},{"a":7,"b":4},{"a":9,"b":12}]}
取值 list["items"][0]["a"]
#5
4楼。假如list = {},我想知道的是:怎样写代码,使得list{"items":{"a":1,"b":2},{"a":7,"b":4},{"a":9,"b":12}}
#6
字典本来就是一个建对一值,从定义与python的语法上你的要求都是不可取的,你顶多只能采取楼上的变通的方法
#7
list = {}
list["items"] = [{"a":1,"b":2},{"a":7,"b":4},{"a":9,"b":12}]
list["items"] = [{"a":1,"b":2},{"a":7,"b":4},{"a":9,"b":12}]
#1
不要使用初始化
#2
你就不能存个list当key吗?
#3
list = {}
list['items'] = [{"a":1,"b":2},{"a":7,"b":4},{"a":9,"b":12}]
这个意思?
#4
可以这样
list = {"items":[{"a":1,"b":2},{"a":7,"b":4},{"a":9,"b":12}]}
取值 list["items"][0]["a"]
list = {"items":[{"a":1,"b":2},{"a":7,"b":4},{"a":9,"b":12}]}
取值 list["items"][0]["a"]
#5
4楼。假如list = {},我想知道的是:怎样写代码,使得list{"items":{"a":1,"b":2},{"a":7,"b":4},{"a":9,"b":12}}
#6
字典本来就是一个建对一值,从定义与python的语法上你的要求都是不可取的,你顶多只能采取楼上的变通的方法
#7
list = {}
list["items"] = [{"a":1,"b":2},{"a":7,"b":4},{"a":9,"b":12}]
list["items"] = [{"a":1,"b":2},{"a":7,"b":4},{"a":9,"b":12}]