[Tutor] checking within a table for identity
Sheila King
sheila@thinkspot.net
Mon, 07 May 2001 06:04:46 -0700
On Mon, 07 May 2001 02:21:01 -0500, "Julieta Rangel"
<julieta_rangel@hotmail.com> wrote about [Tutor] checking within a table for
identity:
:
:As you might see, the set {e,a,b,ab} has an identity element, which is e. If
:you check, e*a=a and a*e=a, so e is the identity element of the set. As you
:can see, you have to do this for every element within the set. What I need
:to do is to "check whether there is an item in the set, where (item,
:whatever)== whatever, for each whatever in the set, and also check whether
:(whatever, item) == whatever." (I'm quoting from one of you guys, I believe
:it is from Ms. King). Does anyone have any suggestions?
I would probably write a function
IsIdentityElement(elt, set)
Where the function would take the element, and check for each item in the set if
(elt, item) == item
and
(item, elt) == item
This would require a loop. (Sometime like for item in set: )
I would have IsIdentity Element return a 1 if the elt turned out to be the
Identity Element, and have it return 0, otherwise.
Probably I'd have it test for
not (elt, item) == item
and
not (item, elt) == item
And if it came out to be the case, that it was not the identity element, return
0 immediately (which would make it break out of the loop. If I made it through
all the loops without breaking out and returning a zero, have it return 1,
because it passed all the tests and must be the identity element.
When you call it in your script's main body, you need a loop there, too, to
check for all the items in the set, whether any one of them might be the
identity element.
for elt in set:
if IsIdentityElement(elt, set):
print "found the identity element. It is ", elt
break
Well, maybe that will give you a starting idea?
--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/