composition

How to communicate between sibling objects in Python, when using Composition, not Inheritance

How to communicate between sibling objects in Python, when using Composition, not Inheritance Question: I have a parent object which is composed of 2 (different) child objects. The 2 child instances need to communicate. For example, assume child1 needs to send something to child2: import children class Parent: def __init__(self): self.child1 = children.Child1(self.q) self.child2 = …

Total answers: 2

Composing functions in python

Composing functions in python Question: I have an array of functions and I’m trying to produce one function which consists of the composition of the elements in my array. My approach is: def compose(list): if len(list) == 1: return lambda x:list[0](x) list.reverse() final=lambda x:x for f in list: final=lambda x:f(final(x)) return final This method doesn’t …

Total answers: 16