So, there is an easy way to calculate the intersection of two sets through set.intersection (). However, I have the following problem:
class Person(Object):
def __init__(self, name, age):
self.name = name
self.age = age
l1 = [Person("Foo", 21), Person("Bar", 22)]
l2 = [Person("Foo", 21), Person("Bar", 24)]
union_list = list(set(l1).union(l2))
( Objectis the base class provided by my ORM, which implements the basic functions __hash__and __eq__which essentially adds each member of the class to the hash. In other words, the return __hash__be the hash of each element of the class)
At this point I would like to run the intersection operation only with the help of .nameto find, let's say Person('Bar', -1).intersection(union_list) #= [Person("Bar", -1), Person("Bar", 22), Person("Bar", 24)]. (typical .intersection()at this point will not give me anything, I cannot override __hash__either __eq__in the class Person, as this will replace the original union of the set (I think)
What is the best way to do this in Python 2.x?
EDIT: , set. , , , , ( , , , , !)