
On 9/29/2015 9:20 AM, Rob Cliffe wrote: Why not
def __init__(self, vertices=None, edges=None, weights=None, source_nodes=None): self.vertices = vertices if vertices is not None else [] self.edges = edges if edges is not None else [] self.weights = weights if weights is not None else {} self.source_nodes = source_nodes if source_nodes is not None else []
I don't understand why not:
self.vertices = vertices or [] self.edges = edges or [] self.weights = weights or {} self.source_nodes = source_nodes or []
Emile
A further virtue of self.vertices = vertices or [] and the like is that they coerce falsy parameters of the wrong type to the falsy object of the correct type. E.g. if vertices is '' or 0, self.vertices will be set to [], whereas the ternary expression only tests for not-None so self.vertices will be set to a probably crazy value.