[Tutor] checking if all items in a list are the same
Sean 'Shaleh' Perry
shaleh@valinux.com
Mon, 07 May 2001 15:30:50 -0700 (PDT)
On 07-May-2001 Julieta Rangel wrote:
> If I have a list, how can I compare all of the elements to check if they are
> the same? Say that I have the following list:
>
> [e,e,e,e,e]
>
> How can I tell the computer to go item by item in the list and compare them.
> If they are the same, I want the computer to tell me that it has found the
> identity element, and if they are not the same, I want the computer to tell
> me that there is no identity element. Can anyone help?
>
Often times it helps to consider the problem as a person would the very
first time.
"How do I tell if a bunch of things are the same?" Hmm, I would take an item
and then look at another item and decide if they are the same. Then while
still holding that first item in mind, I would look at all of the items. Along
the way I might notice that some items are like others but not the first item I
chose.
Sure, this may not be the best way, but it is always more important to get
something working, then make it work at maxmimum efficiency.