How to convert a list to a list of tuples?

后端 未结 7 1769
陌清茗
陌清茗 2020-11-27 02:52

I am newbie to Python and need to convert a list to dictionary. I know that we can convert a list of tuples to a dictionary.

This is the input list:



        
7条回答
  •  心在旅途
    2020-11-27 03:31

    Using slicing?

    L = [1, "term1", 2, "term2", 3, "term3"]
    L = zip(L[::2], L[1::2])
    
    print L
    

提交回复
热议问题