From f974fc316df8f1cd22e96ff61a0d8345955934e7 Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Fri, 5 Jun 2015 18:02:46 +0200 Subject: [PATCH] Use intersection method of header Rather than manually implement that with 2 for loops --- relational/relation.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/relational/relation.py b/relational/relation.py index 928cca6..d7b9ce3 100644 --- a/relational/relation.py +++ b/relational/relation.py @@ -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__()