<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def nmltostring(nml):
 """Convert a dictionary representing a Fortran namelist into a string."""

    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