Update some snippets

This commit is contained in:
Angelos Chalaris
2019-08-20 10:45:53 +03:00
parent 8a0fd59a72
commit 08810dd64e
7 changed files with 31 additions and 101 deletions

View File

@@ -1,14 +1,15 @@
---
title: has_duplicates
tags: list
tags: list,beginner
---
Checks a flat list for duplicate values. Returns True if duplicate values exist and False if values are 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 there are duplicate values in a flast list, `False` otherwise.
Use `set()` on the given list to remove duplicates, compare its length with the length of the list.
```py
def has_duplicates(lst):
return len(lst) != len(set(lst))
return len(lst) != len(set(lst))
```
```py