Use intersection method of header

Rather than manually implement that with 2 for loops
master
Salvo 'LtWorf' Tomaselli 2015-06-05 18:02:46 +07:00
parent c8db7b619c
commit f974fc316d
1 changed files with 9 additions and 4 deletions

@ -289,10 +289,7 @@ class relation (object):
problems when saving the relation.
Just like natural join, it works considering shared attributes.'''
shared = []
for i in self.header.attributes:
if i in other.header.attributes:
shared.append(i)
shared = self.header.intersection(other.header)
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'''
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):
'''Returns String representation of the field's list'''
return self.attributes.__str__()