Are all items in list the same?

Chris Angelico rosuav at gmail.com
Mon Jan 7 20:28:46 EST 2019


On Tue, Jan 8, 2019 at 12:26 PM Tim Chase <python.list at tim.thechases.com> wrote:
>   def all_equal(iterable):
>     i = iter(iterable)
>     first = next(i)
>     return all(x == first for x in i)
>
> And I even like how nicely it reads :-)

Yes, there's something beautiful about writing "first = next" :-)

ChrisA



More information about the Python-list mailing list