0

I have a dictionary like this: d = {"name": "john", "surname": "smith", "nickname: "john"}

I want to get all unique values, i.e: ["john", "smith"]

I have see this question which does the same a for list of dictionaries, and I have seen this question which uses values() but it does not return the unique list of values.

Hooman Bahreini
  • 14,480
  • 11
  • 70
  • 137

2 Answers2

3

you can convert the value of a dict to a set to remove the duplicate and pass it back to a list list(set(d.values()))

dtlam26
  • 1,410
  • 11
  • 19
1

You can use set

unique = list(set(d.values()))
RichieV
  • 5,103
  • 2
  • 11
  • 24