Python program to get the sum of unique elements from dictionary list values.

In this python dictionary program, we will get the sum of unique elements from dictionary list values.

Steps to solve the program
  1. Take a dictionary with the value list as input and create an empty list.
  2. Use for loop to iterate over the value list of the dictionary.
  3. Add unique elements from the value list to the empty list using a nested for loop and an if statement.
  4. Get the sum of the list using sum().
  5. Print the output.
				
					D1 = {'a':[6,7,2,8,1],'b':[2,3,1,6,8,10],'d':[1,8,2,6,9]}
l = []

for v in D1.values():
    for num in v:
        if num not in l:
            l.append(num)
            
print("Sum: ",sum(l))
				
			

Output :

				
					Sum:  46
				
			

reverse each string value in the dictionary and add an underscore before and after the Keys.

Leave a Comment