[Python] How to create a dictionary which will have common keys

Discussão em 'Python' iniciado por Stack, Agosto 29, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to create a Dictionary using keys and Values

    keys = [1,2,3,4,5,1,1,2,2,3,4,4,5,6,7,7,8,9]


    and values.

    values = ['a', 'b' , 'c' ,'d', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l']


    using zip function or using a for loop.

    dict1 = dict(zip(keys, values))
    print(dict1)


    The output is.

    {1: 'g', 2: 'i', 3: 'j', 4: 'l', 5: 'm', 6: 'n', 7: 'p', 8: 'q', 9: 'r'}


    But the dict ignores the values for common keys. Like it ignores 1: 'a' and many more.

    Please tell me a way to deal with it.

    Continue reading...

Compartilhe esta Página