[Tutor] cross product
Julieta Rangel
julieta_rangel@hotmail.com
Sun, 06 May 2001 21:56:35 -0500
I've been playing with the cross product definition Daniel gave me. It makes
a
lot of sense, and I'm sure it will make it a lot easier for me to prove
associativity; however, I'm doing something wrong because when I run it, I
don't get the result I thought I would. Would you take a look and tell me
what I'm doing wrong?
def cross(set1,set2):
resulting_set = []
for s1 in set1:
for s2 in set2:
resulting_set.append( (s1, s2) )
return resulting_set
set = ['e','a','b', 'ab']
print set
s = cross(set,cross(set,set))
print s
When I run it, I get the following:
['e', 'a', 'b', 'ab']
[('e', ('e', 'e'))] #Shouldn't I get 64 pairs here instead of one?
I thought that a loop would do the trick, but I couldn't figure out how to
do it. Can you help? I want to get the entire 64 pairs on my printout.
Julieta
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com