Files
30-seconds-of-code/snippets/unique_elements.md
2019-08-20 11:18:55 +03:00

18 lines
308 B
Markdown

---
title: unique_elements
tags: list,beginner
---
Returns the unique elements in a given list.
Create a `set` from the list to discard duplicated values, then return a `list` from it.
```py
def unique_elements(li):
return list(set(li))
```
```py
unique_elements([1, 2, 2, 3, 4, 3]) # [1, 2, 3, 4]
```