<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def convert_to_yaml(cfg, str_or_buffer):
 """ Convert a dictionary to YAML and return the string or write it out depending on the type of `str_or_buffer`. Parameters cfg : dict or OrderedDict Dictionary or OrderedDict to convert. str_or_buffer : None, str, or buffer If None: the YAML string will be returned. If string: YAML will be saved to a file. If buffer: YAML will be written to buffer using the ``.write`` method. Returns ------- str or None YAML string if `str_or_buffer` is None, otherwise None since YAML is written out to a separate destination. """

    order = None
    if isinstance(cfg, OrderedDict):
        order = []

    s = ordered_yaml(cfg, order)

    if not str_or_buffer:
        return s
    elif isinstance(str_or_buffer, str):
        with open(str_or_buffer, 'w') as f:
            f.write(s)
    else:
        str_or_buffer.write(s)