code: def defaultsnamedtuple(name, fields, defaults=None):
      '''
      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
      '''
      nt = collections.namedtuple(name, fields)
      nt.__new__.__defaults__ = (None,) * len(nt._fields)
      if isinstance(defaults, collections.Mapping):
          nt.__new__.__defaults__ = tuple(nt(**defaults))
      elif defaults:
          nt.__new__.__defaults__ = tuple(nt(*defaults))
      return nf defaultsnamedtuple(name, fields, defaults=None):
      '''
      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
      '''
      nt = collections.namedtuple(name, fields)
      nt.__new__.__defaults__ = (None,) * len(nt._fields)
      if isinstance(defaults, collections.Mapping):
          nt.__new__.__defaults__ = tuple(nt(**defaults))
      elif defaults:
          nt.__new__.__defaults__ = tuple(nt(*defaults))
      return nt
docs: 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