# Python find unique values in list

posted Feb 22

## Overview

Today we will see in our website Kodlogs how in python we can find the unique value from the list.We can also find the unique value from the set function.we can also find the unique value by loop..

## Duplicate Num:special values in a list

``num = [1, 1, 2, 2, 3, 3,4,4,5]``

## Output unique num

``unique_num = [1, 2, 3, 4, 5]``

## Using a Set().

Using a set one way to go about it. A set is beneficial due to the fact it consists of special elements.

You can use a set to get the special elements. Then, flip the set into a list.Let’s seem to be at two procedures that use a set and a list. The first strategy is verbose, however it’s beneficial to see what’s occurring every step of the way.

``````numbers = [1, 2, 2, 3, 3, 4, 5 ,5,6,6,7,7]

def get_unique_numbers(Numbers):

list_of_unique_numbers = []

unique_numbers = set(Numbers)

for number in unique_numbers:
list_of_unique_numbers.append(Number)

return list_of_unique_numbers

print(get_unique_numbers(numbers))``````

## OUTPUT

``[1,2,3,4,5,6,7]``

## Using loop

The foremost concept is to create an empty listing that’ll preserve special numbers. Then, use a for loop iterate over every range in the given list. If the range is already in the special list, then proceed on to the subsequent iteration. Otherwise, add the wide variety to it.

Let's seem at two methods to use new release to get the special values in a list, beginning with the extra verbose one.

``````numbers = [100, 100, 200, 300, 400]

def get_unique_numbers(numbers):
unique = []

for number in numbers:
if number in unique:
continue
else:
unique.append(number)
return unique

print(get_unique_numbers(numbers))
``````

## OUTPUT

``[100,200,300,400]``

## Loop

`````` for number in numbers:
if number in unique:
continue
else:
unique.append(number)``````

110 points
7