python2列表转换为字典
将列表转换为字典。#!/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-...
·
将列表转换为字典。
#!/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}
更多推荐
所有评论(0)