I am trying to add items to a list in a dictionary. I have two lists: x_list and y_list. I am trying to make x_list the keys and y_list the values. I have tried using a zip method but I really need to add them one by one. Right now I have:
dictionary = dict((x,0) for x in x_list)
but I would like to have something like:
dictionary = dict((x,y) for x in x_list, for y in y_list)
but obviously this is creating a syntax error. Is there any way to do this? Thank you!
EDIT:
I have tried zipping and it works, thank you, but I need to add the items to the dictionary one by one (I'm trying to have entries with the same keys add the values together for instance apple:10 and apple:5 become apple:15)
FOR EXAMPLE:
x_list = (blue, orange, purple, green, yellow, green, blue)
y_list = (1, 2, 5, 2, 4, 3, 8)
I would like the output to be
dictionary = {blue:9, orange:2, purple:5, green:5, yellow:4}
and the lists are continuously added to.
dict(zip(x_list,y_list)).Counter