Python Program to create and concatenate n number of dictionaries.

#Python Program to create and concatenate n number of dictionaries.

dic = {}
dict1 = {}

N = int(input("Enter number of dictionaries you want to create:"))

for i in range (N):
    dic["dic%d" % i] = {}
    a= int(input("\nEnter number of items in dictionary %d:"% i))
    list0 = []
    list1 = []
   
    for j in range(a):
        key=input("Enter key for item %d:"% j)
        list0.append(key)

    for k in range(a):
        value=input("Enter value for key "+list0[k]+":")
        list1.append(value)

    for l in range(0,a):
        dic['dic%d'% i][list0[l]] = list1[l]
        if l == a:
            del list0
            del list1


print("\nOriginal dictionaries are:")
for t in range (N):
    print("Dictionary %d"% t,"is:")
    print(dic['dic%d'% t])

for s in range (N):
    dict1.update (dic['dic%d'% s])

print("After concatenating dictionary is:")
print (dict1)

Comments

Popular posts from this blog

Python program to calculate age and year when user will be 100 years old

Python program to print numbers less than 5 from the list.