[Tutor] Counting matching elements in sequences

Gregor Lingl glingl at aon.at
Wed Dec 10 15:18:58 EST 2003



Alan Gauld schrieb:

>>On  9 Dec 2003, Gregor Lingl <- glingl at aon.at wrote:
>>
>>    
>>
>>>What do you think about:
>>>      
>>>
>>> >>> def alleq(seq):
>>>...     return seq == seq[:1]*len(seq)
>>>...
>>>      
>>>
>
>Gregor, I assume you had a reason to use seq[:1]
>instead of seq[0]? But I can't think of any.
>  
>
Hi Alan,
I could have used [seq[0]] instead of seq[:1], but the latter works also
if seq is empty, in which case the first would cause an error. Magnus argued
about empty lists having "all equal" elements.
Gregor





More information about the Tutor mailing list