10 Python Hacks in 30 Seconds

Peng Cao
4 min readApr 20, 2023

1. Checking All Element The Same in A List

def all_equal(lst):
"""
It returns True if all the elements in the list are equal, and False otherwise:param lst: The list to check
:return: True or False
"""
return lst[1:] == lst[:-1]
all_equal([1, 2, 3, 4, 5, 6]) # False
all_equal([1, 1, 1, 1]) # True

2. Checking All Element Unique in A List

--

--

Peng Cao

Writing programming and tech guide; Help each other with followers, thanks mate! Let's version up, V2digital!