将列表转换为字典。

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
 
i = ['abc', 'def']
l = [1001, 10022]
print dict([i,l])

注意python2中print dict在python3中会报错,python3中可使用:

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
 
i = ['abc', 'def']
l = [1001, 10022]
dict([i,l])

运行结果:

{'abc': 'def', 1001: 10022}

当dict(zip(i,l))时,运行结果:

{'abc': 1001, 'def': 10022}
Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐