How to convert this list into dictionary in Python?

后端 未结 2 1445
隐瞒了意图╮
隐瞒了意图╮ 2021-01-12 14:58

I have a list like this:

paths = [[\'test_data\', \'new_directory\', \'ok.txt\'], [\'test_data\', \'reads_1.fq\'], [\'test_data\', \'test_ref.fa\']]
<         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-12 15:13

    can try this also,

    list1=['a','b','c','d']
    list2=[1,2,3,4]
    

    we want to zip these two lists and create a dictionary dict_list

    dict_list = zip(list1, list2)
    dict(dict_list)
    

    this will give:

    dict_list = {'a':1, 'b':2, 'c':3, 'd':4 }
    

提交回复
热议问题