How to convert a list to a list of tuples?

后端 未结 7 1725
陌清茗
陌清茗 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:44

    Try with the group clustering idiom:

    zip(*[iter(L)]*2)
    

    From https://docs.python.org/2/library/functions.html:

    The left-to-right evaluation order of the iterables is guaranteed. This makes possible an idiom for clustering a data series into n-length groups using zip(*[iter(s)]*n).

提交回复
热议问题