def namedtuple_with_defaults(typename, field_names, default_values=None):
if default_values is None:<EOL><INDENT>default_values = []<EOL><DEDENT>T = namedtuple(typename, field_names)<EOL>T.__new__.__defaults__ = (None,) * len(T._fields)<EOL>if isinstance(default_values, Mapping):<EOL><INDENT>prototype = T(**default_values)<EOL><DEDENT>else:<EOL><INDENT>prototype = T(*default_values)<EOL><DEDENT>T.__new__.__defaults__ = tuple(prototype)<EOL>return T<EOL>
Namedtuple with defaults

From: http://stackoverflow.com/questions/11351032/named-tuple-and-optional-keyword-arguments

Usage:
>>> Node = namedtuple_with_defaults('Node', ['val', 'left' 'right'])
>>> Node()
>>> Node = namedtuple_with_defaults('Node', 'val left right')
>>> Node()
Node(val=None, left=None, right=None)
>>> Node = namedtuple_with_defaults('Node', 'val left right', [1, 2, 3])
>>> Node()
Node(val=1, left=2, right=3)
>>> Node = namedtuple_with_defaults('Node', 'val left right', {'right':7})
>>> Node()
Node(val=None, left=None, right=7)
>>> Node(4)
Node(val=4, left=None, right=7)