Dremendo Tag Line

Create dictionary from a given list in Python

Dictionaries - Question 2

In this question, we will see how to create a dictionary from the given lists in Python programming. To know more about dictionaries click on the dictionaries lesson.

Two lists are given below as:

    a=['english','maths','physics','computer','history']
    b=[56,84,92,76,81]

Q2) Write a program in Python to create a dictionary from the above lists as:

    {'english': 56, 'maths': 84, 'physics': 92, 'computer': 76, 'history': 81}

Program

a=['english','maths','physics','computer','history']
b=[56,84,92,76,81]

print('List a:',a)
print('List b:',b)
c=dict()    # An empty dictionary

for i in range(len(a)):
    c[a[i]]=b[i]

print('Dictionary c:')
print(c)

Output

List a: ['english', 'maths', 'physics', 'computer', 'history']
List b: [56, 84, 92, 76, 81]
Dictionary c:
{'english': 56, 'maths': 84, 'physics': 92, 'computer': 76, 'history': 81}
video-poster