list1=[1,2,3,4]
list2=['a','b','c','d']
Now i need to convert them into a dictionary by
final_list = dict(zip(list1,list2))
I need to add values:
1:a,m,o 2:b,y,z ..
It sounds like you want to add multiple values to a single key in a dictionary. Either assign the value of the key an array or another dictionary. Here is how you could assign it an array
list1=[1,2,3,4]
list2=['a','b','c','d']
final_list = dict(zip(list1,list2))
final_list[1] = ['x', 'y', 'z']
print final_list[1]
final_list[1].append('aa')
print final_list[1]
This can also be simply created and modified from scratch, without the unnecessary steps in the beginning
final_list = {1: ['x', 'y', 'z'], 2: 'b', 3: 'c', 4: 'd'}
print final_list[1]
final_list[1].append('aa')
print final_list
You can concatentate to the strings contained in d. There are a few ways, the easiest is to use the += operator:
list1=[1,2,3,4]
list2=['a','b','c','d']
d = dict(zip(list1,list2))
d[1] += ',m,o'
d[2] += ',y,z'
...
Following this dictionary d will be:
{1: 'a,m,o', 2: 'b,y,z', ...}
m,o,y,zcome from. Are these meant to be lists in the dictionary, or strings?