<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><pre>> On 9/29/2015 9:20 AM, Rob Cliffe wrote:
><i> Why not
</i>> ><i>
</i>> ><i> def __init__(self, vertices=None, edges=None, weights=None,
</i>> ><i> source_nodes=None):
</i>> ><i> self.vertices = vertices if vertices is not None else []
</i>> ><i> self.edges = edges if edges is not None else []
</i>> ><i> self.weights = weights if weights is not None else {}
</i>> ><i> self.source_nodes = source_nodes if source_nodes is not None else []
</i>>
> 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
</pre><div><pre>A further virtue of </pre><pre> self.vertices = vertices or []</pre><div><pre>and the like is that they coerce falsy parameters of the wrong type to the falsy object of the correct type.</pre><pre><span class="Apple-style-span" style="font-family: Helvetica; white-space: normal; "><pre>E.g. if vertices is '' or 0, self.vertices will be set to [], whereas the ternary expression only tests </pre><pre>for not-None so self.vertices will be set to a probably crazy value.</pre></span><div><br></div></pre></div></div></body></html>