W3docs

Get unique values from a list in python

In Python, you can use the set() function to get the unique values from a list.

In Python, you can use the set() function to get the unique values from a list. Here is an example:

Get unique values from a list in Python using set function

python— editable, runs on the server

This will output:


[1, 2, 3, 4, 5]

You can also use list comprehension and the in operator.

Get unique values from a list in Python using list comprehension

python— editable, runs on the server

This will output the same result as above.