首页
it技术
登录
6mi
u
盘
搜
搜 索
it技术
把列表转换为字典
把列表转换为字典
it
2024-07-09
43
创建一个全是空列表的字典:
from
collections
import
defaultdict a
=
[
1
,
2
,
3
]
b
=
defaultdict
(
list
)
b
[
"aaa"
]
.
append
(
1
)
# 可以直接append
b
[
"aaa"
]
把两个列表的元素对应起来,创建字典: a
=
[
1
,
2
,
3
]
c
=
[
4
,
5
,
6
]
dict
(
zip
(
a
,
c
)
)
转载请注明原文地址: https://lol.8miu.com/read-17149.html
最新回复
(
0
)