How to remove repeated values from a dictionary?

Asked

Viewed 100 times

0

For example:

A = {2:5,4:5,7:8,9:8,11:10}

Must return B={11:10} to remove the repeated values.

1 answer

0


This can be done with a single command as follows:

from collections import Counter

B = {k: A[k] for k in A if Counter(A.values())[A[k]] == 1}
  • Thanks, it is Beautiful.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.