[Solved] Insert arrays into a dictionary [closed]


This will add a numbered (name, job) pair for each name:

dict = {}
i = 0 # or 1, if you prefer. but it's not proper to start a list from 1 when programming.
while i < len(names):
    dict[i] = (names[i], Jobs[i])
    i = i+1

as a for loop:

for i in id_:
    dict[i] = (names[i-1], Jobs[i-1])

but I prefer the first method as it doesn’t require making a list of numbers first. This is also far more readable than the zip function. I had to do a -1 on each to make the count work, as he starts his numbering with 1.

4

solved Insert arrays into a dictionary [closed]