Set to dict Python

前端 未结 3 862
轮回少年
轮回少年 2021-02-03 17:59

is there any pythonic way to convert a set into a dict?

I got the following set

s = {1,2,4,5,6}

and want the following dict

<         


        
3条回答
  •  情话喂你
    2021-02-03 18:51

    This is also another way to do

    s = {1,2,3,4,5}
    dict([ (elem, 0) for elem in s ])
    

提交回复
热议问题