as i m beginner in python.
I have below 2 lists:
list1 =['abc','cbd','efg']
list2['applicationName','appllicationName','appllicationName']
output i am expected like below:
[{'appllicationName':'abc'},{'appllicationName':'cbd'},{'appllicationName':'efg'}]
using dict,zip function i am getting only below output:
{'appllicationName':'efg'}
please help me resolve this.
>Solution :
I’m not sure about what you want. But I assume you need a list of 3 single dictionaries. But @Manuel ‘s answer with one dictionary seems better to me.
Anyway… Sticking to your example code you can do it like this.
#!/usr/bin/env python3
list1 = ['abc', 'cbd', 'efg']
list2 = ['applicationName', 'appllicationName', 'appllicationName']
# Method 1
result_one = [{key: val} for key, val in zip(list2, list1)]
# Method 2 assumes that the key name is always the same.
key = 'applicationName'
result_two = [{key: val} for val in list1]
Both methods give you
[{'applicationName': 'abc'}, {'applicationName': 'cbd'}, {'applicationName': 'efg'}]