I have a three lists and I would like to build a dictionary using them:
a = [a,b,c]
b = [1,2,3]
c = [4,5,6]
i expect to have:
{'a':1,4, 'b':2,5, 'c':3,6}
All I can do now is:
{'a':1,'b':2, 'c':3}
What should i do?
I have a three lists and I would like to build a dictionary using them:
a = [a,b,c]
b = [1,2,3]
c = [4,5,6]
i expect to have:
{'a':1,4, 'b':2,5, 'c':3,6}
All I can do now is:
{'a':1,'b':2, 'c':3}
What should i do?
You can try this:
a = ["a","b","c"]
b = [1,2,3]
c = [4,5,6]
new_dict = {i:[j, k] for i, j, k in zip(a, b, c)}
Output:
{'b': [2, 5], 'c': [3, 6], 'a': [1, 4]}
If you really want a sorted result, you can try this:
from collections import OrderedDict
d = OrderedDict()
for i, j, k in zip(a, b, c):
d[i] = [j, k]
Now, you have an OrderedDict object with the keys sorted alphabetically.
check this: how to zip two lists into new one i suggest to first zip the b and c lists and then map them into a dictionary again using zip:
a = ['a','b','c']
b = [1,2,3]
c = [4,5,6]
vals = zip(b,c)
d = dict(zip(a,vals))
print(d)
a = ['a','b','c']
b = [1,2,3]
c = [4,5,6]
result = { k:v for k,*v in zip(a,b,c)}
RESULT
print(result)
Promotion_or_Not = "Yes","Yes","No","Yes","Yes","Yes","Yes","No","Yes","No"
Nopay_leave_or_not ="No","No","Yes","Yes","No","Yes","Yes","No","Yes","No"
Last_year_evaluation = "Good","Bad","Moderate","Good","Moderate","Moderate","Good","Bad","Good","Moderate"
mydict = {'Promotion_or_Not': [Promotion_or_Not],'Nopay_leave_or_not': [Nopay_leave_or_not], 'Last_year_evaluation':[Last_year_evaluation] }
print(mydict)