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
  • 12,572
  • 10
  • 52
  • 106

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,141
  • 6
  • 18
1

You can use set

unique = list(set(d.values()))
RichieV
  • 4,988
  • 2
  • 9
  • 24