Add List Element As Value In Dictionary Using Loop In Python [closed]

I have the following dictionary :

numDict = {
    "1" : '0',
    "2" : '0',
    "3" : '0',
    "4" : '0',
    "5" : '0',
    "6" : '0',
    "7" : '0',
    "8" : '0',
    "9" : '0',
    "10" : '0',
    "11" : '0',
    "12" : '0',
}

And the following list :

numList = ['30', ' ', '40', '6', '40', '34', '4', '20', '5', '74', ' ','36']

I want to insert each element of numList as value of numDict using loop, so the value of each key in numDict should be like this :

numDict = {
        "1" : '30',
        "2" : ' ',
        "3" : '40',
        "4" : '6',
        "5" : '40',
        "6" : '34',
        "7" : '4',
        "8" : '20',
        "9" : '5',
        "10" : '74',
        "11" : ' ',
        "12" : '36',
    }

I’m confuse with the way I should insert the list element as dictionary value. Should I loop over dictionary key?

Answer

  1. You can zip the data to pair the keys from numDict and the values from numList

    zip(inumDict, numList)
    > [('1', '30'), ('2', ' '), ('3', '40'), ...]
    
  2. Then create a dict with that mappings

    dict([('1', '30'), ('2', ' '), ('3', '40')])
    > {'1': '30', '2': ' ', '3': '40'}
    

Final code

inumDict = {"1": '0', "2": '0', "3": '0', "4": '0',
            "5": '0', "6": '0', "7": '0', "8": '0',
            "9": '0', "10": '0', "11": '0', "12": '0', }

numList = ['30', ' ', '40', '6', '40', '34', '4', '20', '5', '74', ' ', '36']
result = dict(zip(inumDict, numList))

print(result)