小编Pan*_*hmi的帖子

如何为x创建字典/列表,将y坐标作为键,将数字/字符作为值?

我有这样的数据结构,如下所示:

data = [[(24, 21), (24, 59), (24, 97), (24, 134), (23, 172)],
        [(419, 19), (419, 57), (419, 95), (419, 133), (419, 170), (419, 208), (419, 245)], 
        [(469, 20), (469, 57), (469, 94), (468, 132), (469, 170)]]
Run Code Online (Sandbox Code Playgroud)

我需要这样的结构:

data = [{(24, 21):'1', (24, 59):'2', (24, 97):'3', (24, 134):'4', (23, 172):'0'}, 
        {(419, 19):'1', (419, 57):'2', (419, 95):'3', (419, 133):'4', (419, 170):'0', (419, 208):'x1', (419, 245):'x2'}, 
        {(469, 20):'1', (469, 57):'2', (469, 94):'3', (468, 132):'4', (469, 170):'0'}]
Run Code Online (Sandbox Code Playgroud)

是否有任何代码可以帮助我理清这个结构或动态生成它?哪个更好列出字典内的字典字典内的搜索键来检索值?

python dictionary list coordinates

-1
推荐指数
1
解决办法
1371
查看次数

标签 统计

coordinates ×1

dictionary ×1

list ×1

python ×1