Are all items in list the same?
Neil Cerutti
neilc at norwich.edu
Tue Jan 8 11:31:19 EST 2019
On 2019-01-08, MRAB <python at mrabarnett.plus.com> wrote:
> On 2019-01-08 00:47, ike at koeln.ccc.de wrote:
>> You might do something like
>>
>> if len(a) == 0 or all(i == a[0] for i in a[1:]):
>>
> You don't need to check the length of the list because if the list is
> empty, 'all' will return True anyway.
Neat! I expected that a[0] would be executed in that case,
but it is not.
--
Neil Cerutti
More information about the Python-list
mailing list