Use intersection method of header
Rather than manually implement that with 2 for loops
This commit is contained in:
parent
c8db7b619c
commit
f974fc316d
@ -289,10 +289,7 @@ class relation (object):
|
|||||||
problems when saving the relation.
|
problems when saving the relation.
|
||||||
Just like natural join, it works considering shared attributes.'''
|
Just like natural join, it works considering shared attributes.'''
|
||||||
|
|
||||||
shared = []
|
shared = self.header.intersection(other.header)
|
||||||
for i in self.header.attributes:
|
|
||||||
if i in other.header.attributes:
|
|
||||||
shared.append(i)
|
|
||||||
|
|
||||||
newt = relation() # Creates the new relation
|
newt = relation() # Creates the new relation
|
||||||
|
|
||||||
@ -527,6 +524,14 @@ class header (object):
|
|||||||
'''Returns how many attributes this header has in common with a given one'''
|
'''Returns how many attributes this header has in common with a given one'''
|
||||||
return len(set(self.attributes).intersection(set(other.attributes)))
|
return len(set(self.attributes).intersection(set(other.attributes)))
|
||||||
|
|
||||||
|
def union(self, other):
|
||||||
|
'''Returns the union of the sets of attributes with another header.'''
|
||||||
|
return set(self.attributes).union(set(other.attributes))
|
||||||
|
|
||||||
|
def intersection(self, other):
|
||||||
|
'''Returns the set of common attributes with another header.'''
|
||||||
|
return set(self.attributes).intersection(set(other.attributes))
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
'''Returns String representation of the field's list'''
|
'''Returns String representation of the field's list'''
|
||||||
return self.attributes.__str__()
|
return self.attributes.__str__()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user