Ok so here is my class:
class Vec:
"""
A vector has two fields:
D - the domain (a set)
f - a dictionary mapping (some) domain elements to field elements
elements of D not appearing in f are implicitly mapped to zero
"""
def __init__(self, labels, function):
self.D = labels
self.f = function
I need help creating a function that takes in two vectors, lets say:
u = Vec({'a','b','c'}, {'a':0,'c':1,'b':4})
v = Vec({'A','B','C'},{'A':1})
the function equal:
equal(u,v)
should return:
false
So far I've tried this:
v = Vec({'x','y','z'},{'y':1,'x':2})
u = Vec({'x','y','z'},{'y':1,'x':0})
def equal(u,v):
"Returns true iff u is equal to v"
assert u.D == v.D
for d in v.f:
for i in u.f:
if v.f[d] == u.f[i]:
return True
else:
return False
print (equal(u,v))
I get true which is incorrect because it's only looking at the last value: 'y':1, how can I check for both?