Tim Chase wrote: > def all_equal(iterable): > i = iter(iterable) > first = next(i) > return all(x == first for x in i) > > It's undefined for an empty list (well, it throws a StopIteration > but you can special-case that), but should hand the cases with > 1 element and 2+ elements (both matching and where any item is not > the same). It should work on an iterator as well but will consume the > items in the process. > > And I even like how nicely it reads :-)
If that's why you omitted the try...except use first = next(i, None) -- https://mail.python.org/mailman/listinfo/python-list