def defaultsnamedtuple(name, fields, defaults=None):
nt = collections.namedtuple(name, fields)<EOL>nt.__new__.__defaults__ = (None,) * len(nt._fields)<EOL>if isinstance(defaults, collections.Mapping):<EOL><INDENT>nt.__new__.__defaults__ = tuple(nt(**defaults))<EOL><DEDENT>elif defaults:<EOL><INDENT>nt.__new__.__defaults__ = tuple(nt(*defaults))<EOL><DEDENT>return nt<EOL>
Generate namedtuple with default values.

:param name: name
:param fields: iterable with field names
:param defaults: iterable or mapping with field defaults
:returns: defaultdict with given fields and given defaults
:rtype: collections.defaultdict