Q. Write a program that checks if two same values in a dictionary have different keys.


You can understand by Watching video :-



Answer :-

dic  = eval(input("Enter a dictionary = "))
count = 0
lst = list (dic.values())

for i in lst :
    a = lst.count(i)
    if a > 1 :
        count += a
    for j in lst :
        if i == j :
            lst.remove( j )
            
if count == 0 :
    print( "no values are same " )
else :
    print( count,"values are same ")

Output :-

Enter a dictionary = {"Path":1,"Walla":9,"Portal":1,"Express":2}
2 values are same

>>> 

Enter a dictionary = {"Path":1,"Walla":9,"Portal":5,"Express":2}
no values are same

>>> 

Enter a dictionar = {"Python":2, "C++":3,"Java":2,"CSS":2}
3 values are same

>>>

5 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. What is the purpose of j loop?

    ReplyDelete
    Replies
    1. Please Watch video. I have explained it properly.

      Delete
    2. if i and j were same than the 'j' will be removed because of duplicate values

      Delete
  2. thank for helping

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post