diff --git a/snippets/all_equal.md b/snippets/all_equal.md index 45bdb8b62..bd6b0dff9 100644 --- a/snippets/all_equal.md +++ b/snippets/all_equal.md @@ -5,11 +5,11 @@ tags: list,beginner Checks if all elements in a list are equal. -- Use `[1:]` and `[:-1]` to compare all the values in the given list. +- Use `set()` to eliminate duplicate elements and then use `len()` to check if length is 1. ```py def all_equal(lst): - return lst[1:] == lst[:-1] + return len(set(lst)) == 1 ``` ```py