feihuadao 发表于 2014-12-16 14:23

python list用法求教

遇到这个情况,写的代码好麻烦,有没有简介的写法看起来更pythonic的?
tuple_list = [(1,2,3),(4,5,6)]
des_list = ('name','type','description')

dict_tmp = {}
ret_list = []
for t in tuple_list:
        for x,y in zip(t,des_list):
                dict_tmp = x
        ret_list.append(dict_tmp)
        dict_tmp = {}

ssfjhh 发表于 2014-12-16 16:00

In : tuple_list = [(1,2,3),(4,5,6)]

In : des_list = ('name','type','description')

In : ret_list =

In : ret_list
Out:
[{'type': 2, 'name': 1, 'description': 3},
{'type': 5, 'name': 4, 'description': 6}]

In :

feihuadao 发表于 2014-12-16 17:52

本帖最后由 feihuadao 于 2014-12-16 17:52 编辑

get it!!:wink::wink::wink:

回复 2# ssfjhh
页: [1]
查看完整版本: python list用法求教