Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
List/Iterator versions solution in Clear category for All the Same by Phil15
# List version.
def all_the_same(elements):
return not elements or all(elem == elements[0] for elem in elements)
# Iterator version.
def all_the_same(elements):
elements = iter(elements)
try:
first = next(elements)
except StopIteration:
return True # Empty iterable.
return all(elem == first for elem in elements)
Feb. 28, 2020