Good afternoon dear colleagues! I have maybe quite an obvious question, but it can be considered as quite a mystery to me.
So, I have two custom classes, let it be Class A and Class B. Class B has a property, which contains multiple instances of Class A. It also contains methods to work with this property: add, remove, get single and all instances in this property.
However, apart from standard and quite over questioned deal with MVC pattern, I wonder: what is the most efficient and fast method to remove an object from this property (array) in Python, which implements some customization (e.g. compare objects by id, title and other properties).
I had implemented my own, but it seems way too complicated for such an essential operation.
class Skill:
def __init__(self, id_):
self.id = id_
class Unit:
def __init__(self):
self.skills = []
def get_skills(self):
return self.skills
def get_skill(self, index):
return self.skills[index]
def add_skill(self, skill):
self.skills.append(skill)
def remove_skill(self, skill_to_remove):
self.skills = filter(lambda skill: skill.id != skill_to_remove.id, self.skills)