Reorganize snippets

This commit is contained in:
Angelos Chalaris
2023-05-03 21:19:02 +03:00
parent 7511813169
commit 5c913d20bd
1240 changed files with 992 additions and 0 deletions

22
python/s/all-equal.md Normal file
View File

@ -0,0 +1,22 @@
---
title: Check if list elements are identical
type: snippet
language: python
tags: [list]
cover: fallen-leaves
dateModified: 2020-10-11T13:40:42+03:00
---
Checks if all elements in a list are equal.
- Use `set()` to eliminate duplicate elements and then use `len()` to check if length is `1`.
```py
def all_equal(lst):
return len(set(lst)) == 1
```
```py
all_equal([1, 2, 3, 4, 5, 6]) # False
all_equal([1, 1, 1, 1]) # True
```