From 6f09a1963723b03d3106c0ce10ed1bbee1dc7c47 Mon Sep 17 00:00:00 2001 From: guru kiran <47276342+gurukiran07@users.noreply.github.com> Date: Sun, 11 Oct 2020 12:38:10 +0530 Subject: [PATCH] Use set instead of slicing --- snippets/all_equal.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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