Are all items in list the same?
Serhiy Storchaka
storchaka at gmail.com
Tue Jan 8 09:48:58 EST 2019
08.01.19 11:07, Peter Otten пише:
> Bob van der Poel wrote:
>
>> I need to see if all the items in my list are the same. I was using set()
>> for this, but that doesn't work if items are themselves lists. So,
>> assuming that a is a list of some things, the best I've been able to come
>> up with it:
>>
>> if a.count( targ ) == len(a):
>>
>> I'm somewhat afraid that this won't scale all that well. Am I missing
>> something?
>
> a[1:] == a[:-1]
>
> :)
>
Very clever! It is definitely the shortest solution.
More information about the Python-list
mailing list