[Tutor] all elements equal in tuple or list

Jeff Shannon jeff at ccvcorp.com
Fri Nov 19 04:15:24 CET 2004


Kent Johnson wrote:

> Kent Johnson wrote:
>
>> 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.
>
>
> I decided to write a version of this that behaves 'correctly' for all 
> inputs. What 'correct' means to me is, if the input is not iterable, 
> the function raises an exception; if the input is an empty iterable, 
> the function returns True; otherwise it compares the first element to 
> all the others and reports the result.


So what's the result if you pass in an iterable of length 1?

I *think* (from eyeballing -- I'm too lazy to type it in and try it ;) ) 
that it will return True, and it seems to me that that is probably the 
correct behavior (especially if it's correct for a zero-length 
iterable), but it's a corner case that probably deserves some mention.

Jeff Shannon
Technician/Programmer
Credit International




More information about the Tutor mailing list