python 中字典嵌套列表的方法

时间:2022-09-15 11:31:51

如下所示:

?
1
2
3
4
5
>>> dict={}
>>> dict['list']=[]
>>> dict['list'].append([1,2,3,4])
>>> dict['list'].append([5,6,7])
>>> dict['list'].append([7,8,9,0,10])

输出字典

?
1
2
3
4
>>> dict
{'list': [[1, 2, 3, 4], [5, 6, 7], [7, 8, 9, 0, 10]]}
>>> dict['list']
[[1, 2, 3, 4], [5, 6, 7], [7, 8, 9, 0, 10]]

相关操作:

?
1
2
3
4
5
6
7
8
9
10
>>> len(dict['list'])
3
>>> dict['list'][1]
[5, 6, 7]
>>> dict['list'][0][2]
3
>>> len(dict['list'][0])
4
>>> len(dict['list'][1])
3

以上这篇python 中字典嵌套列表的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/daoxiaxingcai46/article/details/70213346