[Tutor] all elements equal in tuple or list
kent37 at tds.net
Fri Nov 19 03:28:33 CET 2004
The rest of the algorithm will fail if vals is None or an empty list or
tuple. But an empty list, especially, should return True - all of the
elements are the same. Both None and  evaluate to False in a
conditional so this skips the rest of the algoritm in those cases.
It will also return true if vals is the number 0 so maybe it is a bit
over broad, but anyway that is the idea.
In general anything empty or 0 will evaluate to False in a conditional.
Dick Moores wrote:
> Kent, I'm having trouble getting my mind around this. Why do you use "if
> Kent Johnson wrote at 09:15 11/18/2004:
>> def test(vals):
>> if vals:
>> i = iter(vals)
>> first = i.next()
>> for item in i:
>> if first != item:
>> return False
>> return True
> Tutor maillist - Tutor at python.org
More information about the Tutor