python list转dict示例分享
2014-01-28 00:00
981 查看
需求:['1:a','2:b','3:c'] 转换为 {'1′: 'a','3′: 'c','2′: ''}
a = {} b = ['1:a','2:b','3:c'] map(lambda x:a.setdefault(x.split(':')[0], x.split(':')[1]), b) print a {'1': 'a', '3': 'c', '2': 'b'}
相关文章推荐
- python list转dict示例分享
- python抓取网页内容示例分享
- python定时器使用示例分享
- python list中append()与extend()用法分享
- python实现代码行数统计示例分享
- python之列表(list),元组(tuple),集合(set),字典(dict)
- python 函数中或者new一个对象的时候 默认值如果设为list, dict, or sets要注意
- python使用cookielib库示例分享
- Python 中list ,set,dict的大规模查找效率
- Python简单定义与使用字典dict的方法示例
- python 实现将字典dict、列表list中的中文正常显示方法
- Python 函数默认参数不能使用可变对象,如List,dict
- python的dict,set,list,tuple应用详解
- python中list/tuple/dict/set的区别
- Python中list,tuple,dict,set的区别和用法
- Python - 两个列表(list)组成字典(dict)
- Python tricks(3) -- list和dict的遍历和方法
- Python之list,string,tuple,dict练习题
- python 示例分享---逻辑推理编程解决八皇后
- Python基础——list、tuple、dict、set