[Python] Set to dict Python

Discussão em 'Python' iniciado por Stack, Abril 13, 2025.

  1. Stack

    Stack Membro Participativo

    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

    c = {1:0, 2:0, 3:0, 4:0, 5:0, 6:0}


    with a list you would do

    a = [1,2,3,4,5,6]
    b = []

    while len(b) < len(a):
    b.append(0)

    c = dict(itertools.izip(a,b))

    Continue reading...

Compartilhe esta Página