0

I want to create a list of dictionary in the form

my_var = [{'a': 'jack','b': 120}, {'a':'davis', 'b': 150}]

The two lists that I want to use to create the dictionary

j = ['jack', 'davis'] and d = [120, 150] 

I need help in creating the dictionary my_var, how can I do this ?

KalEmm
  • 97
  • 5
  • 1
    Does this answer your question? [Convert two lists into a dictionary](https://stackoverflow.com/questions/209840/convert-two-lists-into-a-dictionary) – Rakesh Aug 20 '20 at 14:13

1 Answers1

0

try this

j = ['jack', 'davis'] 
d = [120, 150] 
my_var  = [dict(zip(('a', 'b'), (j[i], d[i]))) for i  in range(min(len(j), len(d)))]
Kuldip Chaudhari
  • 1,112
  • 4
  • 8