Update syntax highlighting, update allUnique
This commit is contained in:
@ -1,17 +1,18 @@
|
||||
---
|
||||
title: all_unique
|
||||
tags: list
|
||||
tags: list,beginner
|
||||
---
|
||||
Checks a flat list for all unique values. Returns True if list values are all unique and False if list values aren't all unique.
|
||||
|
||||
This function compares the length of the list with length of the set() of the list. set() removes duplicate values from the list.
|
||||
Returns `True` if all the values in a flat list are unique, `False` otherwise.
|
||||
|
||||
``` python
|
||||
Use `set()` on the given list to remove duplicates, compare its length with the length of the list.
|
||||
|
||||
```py
|
||||
def all_unique(lst):
|
||||
return len(lst) == len(set(lst))
|
||||
```
|
||||
|
||||
``` python
|
||||
```py
|
||||
x = [1,2,3,4,5,6]
|
||||
y = [1,2,2,3,4,5]
|
||||
all_unique(x) # True
|
||||
|
||||
Reference in New Issue
Block a user