<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write(nml, nml_path, force=False, sort=False):
 """Save a namelist to disk using either a file object or its file path. File object usage: File path usage: This function is equivalent to the ``write`` function of the ``Namelist`` object ``nml``. By default, ``write`` will not overwrite an existing file. To override this, use the ``force`` flag. To alphabetically sort the ``Namelist`` keys, use the ``sort`` flag. """

    # Promote dicts to Namelists
    if not isinstance(nml, Namelist) and isinstance(nml, dict):
        nml_in = Namelist(nml)
    else:
        nml_in = nml

    nml_in.write(nml_path, force=force, sort=sort)