code: def nmltostring(nml):
      
      if not isinstance(nml,dict):
        raise ValueError("nml should be a dict !")
  
      curstr = ""
      for key,group in nml.items():
         namelist = ["&" + key]
         for k, v in group.items():
           if isinstance(v, list) or isinstance(v, tuple):
             namelist.append(k + " = " + ",".join(map(str, v)) + ",")
           elif is_string(v):
             namelist.append(k + " = '" + str(v) + "',")
           else:
             namelist.append(k + " = " + str(v) + ",")
         namelist.append("/")
  
         curstr = curstr + "\n".join(namelist) + "\n"
  
      return curstr
docs: Convert a dictionary representing a Fortran namelist into a string.